| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- namespace addons\ElectronCoupon\backend\controllers;
- use Yii;
- use common\enums\StatusEnum;
- use addons\Store\common\models\StoreClerkIncome;
- use addons\Store\common\models\StoreClerkIncomeData;
- use common\models\user\User;
- class StoreLogController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 收益明细
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- $get = \Yii::$app->request->get();
- $where = [
- ['mall_id' => $this->mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- if (!empty($get['store_id'])) $where[] = ['store_id' => $get['store_id']];
- $params = ['where' => $where, 'order' => 'id desc', 'with' => 'store'];
- $list = StoreClerkIncomeData::listPage($params);
- if ($list === false) return $this->error(StoreClerkIncomeData::getStaticError());
- return $this->success('ok', $list);
- }
- return $this->render($this->action->id);
- }
- public function actionDetail()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $store_id=$params['store_id'];
- $res = Yii::$app->services->validate->validate($params, [
- [['page', 'user_id','clerk_user_id'], 'integer'],
- [['user_name', 'e_coupon_name', 'check_user_name'], 'string'],
- [['usage_time'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [
- ['mall_id' => $this->mall_id],
- ['store_id' => $store_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- if ($params['user_id']) {
- $where[] = ['=', 'user_id', (int)$params['user_id']];
- }
- if ($params['clerk_user_id']) {
- $where[] = ['clerk_user_id'=>(int)$params['clerk_user_id']];
- }
- // 使用者 昵称、手机号
- if ($params['user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 核销员 昵称、手机号
- if ($params['check_user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['check_user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['check_user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'clerk_user_id', $user_ids];
- }
- if ($params['e_coupon_name']) {
- $where[] = ['like', 'e_coupon_name', "%" . $params['e_coupon_name'] . "%", false];
- }
- // 使用时间
- $start_time = strtotime($params['usage_time'][0] ?? 0);
- $end_time = strtotime($params['usage_time'][1] ?? 0);
- if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) {
- $where[] = ['>=', 'created_at', $start_time];
- $where[] = ['<=', 'created_at', $end_time];
- }
- $condition = ['where' => $where, 'order' => 'id desc'];
- $page_data = StoreClerkIncome::listPage($condition);
- $user_id_array1 = array_column($page_data['list'], 'user_id');
- $user_id_array2 = array_column($page_data['list'], 'clerk_user_id');
- $user_id_array3 = array_column($page_data['list'], 'proper_user_id');
- $user_id_array = array_unique(array_filter(array_merge($user_id_array1, $user_id_array2, $user_id_array3)));
- $users = User::find()
- ->select('id,nickname,avatar_url,mobile')
- ->where(['>=', 'status', StatusEnum::DISABLED])
- ->where(['mall_id' => $this->mall_id])
- ->where(['in', 'id', $user_id_array])
- ->asArray()
- ->all();
- $users_data = array_column($users, null, 'id');
- $page_data['list'] = is_array($page_data['list']) ? $page_data['list'] : [];
- foreach ($page_data['list'] as $index => $item) {
- $item['user'] = $users_data[$item['user_id']] ?? [];
- $item['clerk_user'] = $users_data[$item['clerk_user_id']] ?? [];
- $item['proper_user'] = $users_data[$item['proper_user_id']] ?? [];
- $page_data['list'][$index] = $item;
- }
- if ($page_data === false) return $this->error(StoreClerkIncome::getStaticError());
- return $this->success('ok', compact('page_data'));
- }
- return $this->render($this->action->id);
- }
- public function actionGetTopData()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $store_id=$get['store_id'];
- $params=$get;
- $where[] = 'and';
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['store_id' => $store_id];
- $where[] = ['status' => StatusEnum::ENABLED];
-
- if ($params['user_id']) {
- $where[] = ['=', 'user_id', (int)$params['user_id']];
- }
- if ($params['clerk_user_id']) {
- $where[] = ['clerk_user_id'=>(int)$params['clerk_user_id']];
- }
-
- // 使用者 昵称、手机号
- if ($params['user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 核销员 昵称、手机号
- if ($params['check_user_name']) {
- $user_ids = User::find()
- ->orWhere(['like', 'nickname', "%" . $params['check_user_name'] . "%", false])
- ->orWhere(['like', 'mobile', "%" . $params['check_user_name'] . "%", false])
- ->select('id')
- ->asArray()
- ->column();
- $where[] = ['in', 'clerk_user_id', $user_ids];
- }
-
- if ($params['e_coupon_name']) {
- $where[] = ['like', 'e_coupon_name', "%" . $params['e_coupon_name'] . "%", false];
- }
-
- // 使用时间
- $start_time = strtotime($params['usage_time'][0] ?? 0);
- $end_time = strtotime($params['usage_time'][1] ?? 0);
- if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) {
- $where[] = ['>=', 'created_at', $start_time];
- $where[] = ['<=', 'created_at', $end_time];
- }
- $total_amount = StoreClerkIncome::find()
- ->where($where)
- ->sum('amount');
- $total_amount = $total_amount ? $total_amount : 0;
- $total_income = StoreClerkIncome::find()
- ->where($where)
- ->sum('income');
- $total_time = StoreClerkIncome::find()
- ->where($where)
- ->count();
- $data = [
- 'total_time'=>$total_time??0,
- 'total_amount' => $total_amount??0,
- 'total_income'=>$total_income??0,
- ];
- return $this->success('获取成功', $data);
- }
- }
- }
- }
|