コード例 #1
0
ファイル: ProductService.php プロジェクト: tianyunchong/php
 /**
  * 获得采集商品列表
  * @param  int  $cid    企业id
  * @param  string  $groupid    分组字符串
  * @param  int $offset 分页起始值
  * @param  int $limit  分页
  * @param  string $column  字段  默认为全部
  * @param  string  $order  排序
  */
 public function getCaijiProductList($cid, $groupid = 0, $offset = 0, $limit = 20, $column = '*', $order = ' uptime desc')
 {
     $cid = $this->di['filter']->sanitize($cid, 'int', 0);
     $groupid = $this->di['filter']->sanitize($groupid, 'string', 0);
     $offset = $this->di['filter']->sanitize($offset, 'int', 0);
     $limit = $this->di['filter']->sanitize($limit, 'int', 20);
     if (!empty($groupid)) {
         $pidgid = explode('-', $groupid);
         $gid = isset($pidgid[0]) ? $pidgid[0] : 0;
         $cgid = isset($pidgid[1]) ? $pidgid[1] : 0;
         $condition = 'cid = :cid: and gid=:gid: and cgid=:cgid: and state = 1';
         $bind = array('cid' => $cid, 'gid' => $gid, 'cgid' => $cgid);
         $pidgid = CaijiPdPidgid::find(array($condition, 'bind' => $bind, 'order' => 'pid DESC', 'limit' => $limit, 'offset' => $offset));
         $pidArr = array();
         if (is_object($pidgid)) {
             $pidgid = $pidgid->toArray();
             foreach ($pidgid as $v) {
                 if (isset($v['pid'])) {
                     $pidArr[] = $v['pid'];
                 }
             }
             if (is_array($pidArr)) {
                 $pidArr = implode(',', $pidArr);
             }
             if (!empty($pidArr)) {
                 $data = CaijiPdInfo::find(array('cid = :cid: and pid in (' . $pidArr . ')', 'bind' => array('cid' => $cid), 'columns' => $column));
                 if ($data) {
                     $data = $data->toArray();
                 } else {
                     $data = array();
                 }
             }
         }
         $data['count'] = CaijiPdPidgid::count(array($condition, 'bind' => $bind));
     } else {
         $condition = 'cid = :cid: and state = 1';
         $bind = array('cid' => $cid);
         $data = CaijiPdinfo::find(array($condition, 'bind' => $bind, 'limit' => $limit, 'offset' => $offset, 'order' => $order, 'columns' => $column));
         if ($data) {
             $data = $data->toArray();
         } else {
             $data = array();
         }
         $data['count'] = CaijiPdinfo::count(array($condition, 'bind' => $bind));
     }
     return $data;
 }