Example #1
0
 /**
  * 添加主营小区
  * @param $brokerId
  * @param $saleCommunityData
  * @return bool
  */
 protected function doSaleCommunity($brokerId, $saleCommunityData)
 {
     $saleCommunityList = Model_Mobile_CustomerSaleRange::getBrokerIdRange($brokerId, 2);
     $saleCommunity = array();
     if (!empty($saleCommunityList)) {
         foreach ($saleCommunityList as $key => $val) {
             $saleCommunity[$val['communityId']] = $val;
         }
     }
     $insertData = array();
     if (!empty($saleCommunityData) && is_array($saleCommunityData)) {
         if (count($saleCommunityData) > 10) {
             array_splice($saleCommunityData, 10);
         }
         foreach ($saleCommunityData as $key => $val) {
             if ($saleCommunity[$val['communityId']]) {
                 //unset已经存在的,剩余数据删除
                 unset($saleCommunity[$val['communityId']]);
             } else {
                 //插入的数据
                 $insertData[] = $val;
             }
         }
     }
     if (!empty($saleCommunity)) {
         $deleteDataId = array();
         foreach ($saleCommunity as $key => $val) {
             $deleteDataId[] = $val['id'];
         }
     }
     if (!empty($deleteDataId)) {
         Model_Mobile_CustomerSaleRange::delRangeByBrokerId($brokerId, 2, $deleteDataId);
     }
     $flag = true;
     foreach ($insertData as $val) {
         $data = array();
         $data['communityId'] = $val['communityId'];
         $data['communityName'] = $val['communityName'];
         $data['type'] = 2;
         $data['cityId'] = $this->cityId;
         $data['brokerId'] = $brokerId;
         $data['createTime'] = time();
         $rs = Bll_CustomerRush_Customer::getInstance()->insertCustomerRange($data);
         if (!$rs) {
             $flag = false;
         }
     }
     return $flag;
 }