$this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]], ]; if (!empty($params['user_id'])) $where[] = ['user_id' => $params['user_id']]; if (!empty($params['keyword'])) { $uids = User::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']]]) ->select('id')->column(); if (!empty($uids)) $where[] = ['user_id' => $uids]; } if (!empty($params['store_id'])) $where[] = ['store_id' => $params['store_id']]; $clerk_params = [ 'where' => $where, 'page' => $params['page'], 'limig' => $params['limit'], 'order' => 'id desc', 'with' => ['user', 'store'], ]; $list = HappinessClerk::listPage($clerk_params); return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //获取用户列表 public function searchUser($params) { try { $where = [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ]; if (!empty($params['keyword'])) { $uids = User::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']], ['id' => $params['keyword']]]) ->select('id')->column(); if (!empty($uids)) $where[] = ['id' => $uids]; } //获取已被添加的核销员user_id $clerk_user = HappinessClerk::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], ]); if (!empty($clerk_user)) { $user_id = array_column($clerk_user, 'user_id', 'user_id'); $where[] = ['not in', 'id', $user_id]; } $list = User::listPage([ 'where' => $where, 'page' => 1, 'limit' => 10, ]); return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //查询门店数据 public function searchStore($params) { try { $where = [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ]; if (!empty($params['keyword'])) { $where[] = ['or', ['like', 'store_name', $params['keyword']], ['id' => $params['keyword']]]; } $store_params = [ 'where' => $where, 'page' => $params['page'], 'limit' => $params['limit'], 'order' => 'id desc' ]; $list = HappinessStore::listPage($store_params); return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //添加、编辑核销员 public function addClerk($params) { try { $params['mall_id'] = $this->mall_id; $params['status'] = StatusEnum::ENABLED; $res = HappinessClerk::setData($params); if (!$res) throw new Exception(HappinessClerk::$static_error); return true; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //删除核销员 public function deleteClerk($params) { try { //查询是否存在该核销员 $info = HappinessClerk::getOne([ ['mall_id' => $this->mall_id], ['id' => $params['id']], ]); if (empty($info)) throw new Exception('不存在该核销员'); $info->status = StatusEnum::DELETE; if (!$info->save()) throw new Exception('删除失败'); return true; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } public function clerkLogList($params) { try { $where = [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ]; if (!empty($params['store_id'])) $where[] = ['store_id' => $params['store_id']]; if (!empty($params['order_no'])) $where[] = ['order_no' => $params['order_no']]; if (!empty($params['date_start'])) $where[] = ['>=', 'created_at', strtotime($params['date_start'])]; if (!empty($params['date_end'])) $where[] = ['<=', 'created_at', strtotime($params['date_end'])]; if (!empty($params['user_keyword'])) { //获取用户数据 $uids = User::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['or', ['like', 'nickname', $params['user_keyword']], ['like', 'mobile', $params['user_keyword']], ['like', 'id', $params['user_keyword']]]) ->select('id')->column(); if (empty($uids)) { $where[] = ['user_id' => 0]; } else { $where[] = ['user_id' => $uids]; } } if (!empty($params['clerk_keyword'])) { //获取用户数据 $uids = User::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['or', ['like', 'nickname', $params['clerk_keyword']], ['like', 'mobile', $params['clerk_keyword']], ['like', 'id', $params['clerk_keyword']]]) ->select('id')->column(); if (empty($uids)) { $where[] = ['user_id' => 0]; } else { $clerk_ids = HappinessClerk::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['user_id' => $uids]) ->select('id')->column(); if (empty($clerk_ids)) { $where[] = ['clerk_id' => 0]; } else { $where[] = ['clerk_id' => $clerk_ids]; } } } $clerk_params = [ 'where' => $where, 'page' => $params['page'], 'limit' => $params['limit'], 'order' => 'id desc', 'with' => ['store', 'clerkUser', 'user'], ]; $list = HappinessClerkLog::listPage($clerk_params); return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //获取门店核销记录数据列表 public function storeClerkLog($params) { try { $where = [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ['store_id' => $this->store_id], ]; if (!empty($params['order_no'])) $where[] = ['order_no' => $params['order_no']]; if (!empty($params['user_id'])) $where[] = ['user_id' => $params['user_id']]; if (!empty($params['clerk_id'])) { //获取用户数据 $clerk_ids = HappinessClerk::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['user_id' => $params['clerk_id']]) ->select('id')->column(); if (empty($clerk_ids)) { $where[] = ['clerk_ids' => 0]; } else { $where[] = ['clerk_id' => $clerk_ids]; } } $clerk_params = [ 'where' => $where, 'order' => 'id desc', 'page' => $params['page'], 'limit' => $params['limit'], 'with' => ['clerkUser', 'user', 'detail'] ]; $list = HappinessClerkLog::listPage($clerk_params); if (!empty($list['list'])) { //获取门店商品 $goods_list = HappinessStoreGoods::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['store_id' => $this->store_id], ['status' => StatusEnum::ENABLED], ['is_on_sale' => 1], ], 'with' => ['good'], 'index' => 'goods_id' ]); foreach ($list['list'] as &$item) { foreach ($item['detail'] as $key => $value) { $item['detail'][$key]['cover_pic'] = $goods_list[$value['goods_id']]['good']['cover_pic']; } } } return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //获取核销记录详情 public function clerkLogDetail($params) { try { $where = [ 'mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'id' => $params['id'], ]; $info = HappinessClerkLog::find()->where($where)->with(['clerkUser', 'user', 'detail'])->asArray()->one(); if (!empty($info)) { $goods_list = HappinessStoreGoods::lists([ 'where' => [ ['mall_id' => $params['mall_id']], ['store_id' => $params['store_id']], ['status' => StatusEnum::ENABLED], ['is_on_sale' => 1], ], 'with' => ['good'], 'index' => 'goods_id' ]); foreach ($info['detail'] as &$item) { $item['cover_pic'] = $goods_list[$item['goods_id']]['good']['cover_pic']; } } return $info; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } public function changeClerkStatus($params) { try { //查询核销员 $clerk_info = HappinessClerk::getOne([ ['mall_id' => $this->mall_id], ['store_id' => $this->store_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]], ['id' => $params['id']], ]); if (empty($clerk_info)) throw new Exception('查无此核销员'); $clerk_info->status = $params['status']; if (!$clerk_info->save()) throw new Exception('操作失败'); return true; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } }