Ejemplo n.º 1
0
 /**
  * 活动产品关联搜索
  * @param  array  $options 搜索条件
  * [
  *     'page' => '页码',
  *     'product_name' => '产品名',
  *     'user_name' => '发布人姓名',
  *     'nickname' => '发布人昵称',
  *     'mobile' => '电话',
  *     'status' => '活动状态',
  *     'activity' => '活动',
  * ]
  * @return [type]          [description]
  */
 public function search($options = [])
 {
     $df = ['page' => 1, 'product_name' => '', 'user_name' => '', 'nickname' => '', 'mobile' => '', 'status' => 0, 'activity' => 0];
     $options = array_merge($df, $options);
     $statusFields = [self::STATUS_SAVE, self::STATUS_VERIFYING, self::STATUS_VERIFY_THROUGH, self::STATUS_VERIFY_NOTTHROUGH];
     $activitiesFields = ['7' => '365', '8' => '一呼百应', '9' => '中国好产品'];
     $activitiesFields = array_keys($activitiesFields);
     $options['status'] = in_array($options['status'], $statusFields) ? $options['status'] : 0;
     $options['activity'] = in_array($options['activity'], $activitiesFields) ? $options['activity'] : 0;
     $choose = [self::tableName() . '.status ' => $options['status'], self::tableName() . '.acti_id ' => $options['activity']];
     $choose = array_filter($choose);
     $offset = ($options['page'] - 1) * self::ACT_PAGESIZE;
     $data = self::find()->joinWith(['member' => function ($query) {
         $query->select([Member::tableName() . '.uid', Member::tableName() . '.truename', Member::tableName() . '.nickname', Member::tableName() . '.mobile', Member::tableName() . '.email']);
     }, 'activity' => function ($query) {
         $query->select([ActivityBase::tableName() . '.id', ActivityBase::tableName() . '.subject', ActivityBase::tableName() . '.summary']);
     }, 'product' => function ($query) {
         $query->select([IProductBase::tableName() . '.id', IProductBase::tableName() . '.name']);
     }])->where(self::tableName() . '.status != :del', [':del' => self::STATUS_INVALID])->andFilterWhere(['like', IProductBase::tableName() . '.name', $options['product_name']])->andFilterWhere(['like', Member::tableName() . '.truename', $options['user_name']])->andFilterWhere(['like', Member::tableName() . '.nickname', $options['nickname']])->andFilterWhere(['like', Member::tableName() . '.mobile', $options['mobile']])->andFilterWhere($choose)->offset($offset)->limit(self::ACT_PAGESIZE)->orderBy([self::tableName() . '.id' => SORT_DESC]);
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * 搜索
  * @param  integer $page    第几页
  * @param  array   $options  搜索参数
  * [
  *     'name' =>'产品名',
  *     'usrname' => '发布人名',
  *     'status' => '产品状态',
  *     'mobile' => '发布人电话'
  * ]
  * @return AR       $products  查询中间结果
  */
 public function search($page = 1, $options = [])
 {
     $df = ['name' => '', 'username' => '', 'status' => '', 'mobile' => ''];
     $options = array_merge($df, $options);
     $offSet = ($page - 1) * self::PAGE_SIZE;
     $products = self::find()->joinWith('user')->where('status != :del', [':del' => 0])->andFilterWhere(['status' => $options['status']])->andFilterWhere(['like', 'name', $options['name']])->andFilterWhere(['like', Member::tableName() . '.username', $options['username']])->andFilterWhere(['like', Member::tableName() . '.mobile', $options['mobile']])->orderBy(['id' => SORT_DESC])->offset($offSet)->limit(self::PAGE_SIZE);
     return $products;
 }