Ejemplo n.º 1
0
 /**
  * 添加产品的单个分组
  * @param ing $gid   分组id
  * @param ing $pid   产品id
  * @param ing $supid 供应商id
  */
 public function addGoodsGroup($pidgid, $pid, $supid, $cid)
 {
     $pidgid = explode('-', $pidgid);
     $gid = isset($pidgid[0]) ? intval($pidgid[0]) : 0;
     $cgid = isset($pidgid[1]) ? intval($pidgid[1]) : 0;
     $state = $online = 1;
     if (!is_array($pid)) {
         $pid = array($pid);
     }
     if (is_array($pid)) {
         $this->di['gcproinfo']->begin();
         foreach ($pid as $v) {
             //判断是否超过3条的限制
             $count = \Gcproinfo\Models\PdPidgid::count(array('pid = :pid: and cid = :cid: and state in(0,1)', "bind" => array('pid' => $v, 'cid' => $cid)));
             if ($count >= 3) {
                 continue;
             } else {
                 //判断是否有重复的分组
                 $count = \Gcproinfo\Models\PdPidgid::count(array('pid = :pid: and gid=:gid: and cgid=:cgid: and state in (0,1)', "bind" => array('pid' => $v, 'gid' => $gid, 'cgid' => $cgid)));
                 if ($count > 0) {
                     continue;
                 } else {
                     $info = \Gcproinfo\Models\Pdinfo::findFirst(array('pid = :pid: and cid = :cid:', 'bind' => array('pid' => $v, 'cid' => $cid)));
                     if (isset($info->state)) {
                         $state = $info->state;
                     }
                     if (isset($info->online)) {
                         $online = $info->online;
                     }
                     $pidgidModel = new \Gcproinfo\Models\PdPidgid();
                     $pidgidModel->pid = $v;
                     $pidgidModel->gid = $gid;
                     $pidgidModel->cid = $cid;
                     $pidgidModel->supid = $supid;
                     $pidgidModel->cgid = $cgid;
                     $pidgidModel->state = $state;
                     $pidgidModel->online = $online;
                     $re = $pidgidModel->save();
                     if ($re == false) {
                         $this->di['gcproinfo']->rollback();
                         return $this->outputData(false, '600', '处理失败');
                         exit;
                     }
                 }
             }
         }
         if (empty($cgid)) {
             $groupobj = \Gcproinfo\Models\Pdcustomgroup::findFirst(array('cid=:cid: and gid = :gid: and parentgid=0', 'bind' => array('gid' => $gid, 'cid' => $cid)));
         } else {
             $groupobj = \Gcproinfo\Models\Pdcustomgroup::findFirst(array('cid=:cid: and gid = :cgid: and parentgid=:gid:', 'bind' => array('cgid' => $cgid, 'gid' => $gid, 'cid' => $cid)));
         }
         if (!empty($groupobj) && is_object($groupobj)) {
             if ($groupobj->pronum > 0) {
                 $groupobj->pronum = $groupobj->pronum + 1;
                 $re2 = $groupobj->save();
                 if ($re2 == false) {
                     $this->di['gcproinfo']->rollback();
                     return $this->outputData(false, '600', '处理失败');
                     exit;
                 }
             }
         }
         $this->di['gcproinfo']->commit();
         return $this->outputData(1);
         exit;
     }
     return $this->outputData(false, '600', '处理失败');
 }
Ejemplo n.º 2
0
 /**
  * 功能说明:企业自定义产品分组
  **/
 public function refreshCustomGroup($cid)
 {
     $groupArr = array();
     if ($cid) {
         $sort = Pdgroupsort::findFirst(array("conditions" => "cid = :cid:", "bind" => array('cid' => $cid)));
         if ($sort) {
             $sort = $sort->toArray();
             isset($sort['gidsort']) && ($sortArr = json_decode($sort['gidsort'], true));
         }
         if (isset($sortArr) && !empty($sortArr)) {
             $grouprs = Pdcustomgroup::find(array("conditions" => "cid = :cid: and state=1", "bind" => array('cid' => $cid)));
             if ($grouprs) {
                 $customGroupRs = $grouprs->toArray();
                 foreach ($customGroupRs as $value) {
                     $customGroupArr[$value['gid']] = $value;
                 }
                 foreach ($sortArr as $value) {
                     if (isset($customGroupArr[$value]) && $customGroupArr[$value]) {
                         $groupArr[$value] = $customGroupArr[$value];
                         unset($customGroupArr[$value]);
                     }
                 }
             }
         } else {
             $grouprs = Pdcustomgroup::find(array("conditions" => "cid = :cid: and state=1", "bind" => array('cid' => $cid)));
             if ($grouprs) {
                 $groupArr = $grouprs->toArray();
             }
         }
         return $groupArr;
     } else {
         return '';
     }
 }