where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('id, pay_price, order_no, is_pay, created_at')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); // $count = count($scan_order); // 总条数 // $start = ($page - 1) * $limit; // 偏移量,当前页-1乘以每页显示条数 // $order = array_slice($scan_order, $start, $limit); foreach ($list as $key => $value) { $list[$key]['goods_name'] = '当面付'; $goods_id = OrderDetail::findOne(['order_id' => $value['id']])->goods_id; $list[$key]['goods_pic'] = Goods::findOne($goods_id)->cover_pic; $list[$key]['type'] = 'scan'; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } /** * 核销员待核销订单,目前只有积分兑换订单 2021-06-30 */ public function actionNotClerkOrderList() { // $current_user = User::findOne(['id' => get_user_id(), 'is_delete' => User::USER_NOT_DELETE, 'is_saas_clerk' => 1, 'store_id' => get_store_id()]); $current_user = MdStaff::findOne(['store_id' => get_store_id(), 'saas_user_id' => get_saas_user_id(), 'is_delete' => 0]); if (!$current_user) { return $this->asJson([ 'code' => 1, 'msg' => '您不是核销员,无法核销订单!' ]); } $page = get_params('page', 1); $limit = get_params('limit', 10); $user_id = get_params('user_id'); // $user = User::findOne($user_id); // $clerk = Clerk::findOne(['user_id' => get_user_id(), 'is_delete' => 0]); // if (!$user || !$clerk) { // return $this->asJson([ // 'code' => 0, // 'msg' => 'success', // 'data' => [ // 'row_count' => 0, // 'page_count' => 0, // 'list' => [], // ] // ]); // } $query = SaasIntegralOrder::find()->where(['store_id' => get_store_id(), 'user_id' => $user_id, 'is_clerk' => 0, 'is_delete' => 0]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as $key => $value) { $goods = Goods::findOne($value['goods_id']); $list[$key]['goods_pic'] = $goods->cover_pic; $list[$key]['goods_name'] = $goods->name; $list[$key]['type'] = 'integral'; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } /** * 联盟订单,目前只有积分兑换订单 2021-06-30 */ public function actionLeagueOrderList() { $page = get_params('page', 1); $limit = get_params('limit', 10); $user_id = get_saas_user_id(); $query = SaasIntegralOrder::find()->where(['user_id' => $user_id, 'is_delete' => 0]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as $key => $value) { $goods = Goods::findOne($value['goods_id']); $list[$key]['goods_pic'] = $goods->cover_pic; $list[$key]['goods_name'] = $goods->name; $list[$key]['type'] = 'integral'; $list[$key]['shop'] = [ 'latitude' => '', 'longitude' => '', 'address' => '', ]; // 获取商城坐标信息 $store = Store::findOne($value['store_id']); if ($store) { if (!empty($store->coordinate)) { list($latitude, $longitude) = explode(',', $store->coordinate); $list[$key]['shop']['latitude'] = $latitude; $list[$key]['shop']['longitude'] = $longitude; } $list[$key]['shop']['address'] = $store->address; $list[$key]['shop']['name'] = $store->name; $list[$key]['shop']['logo'] = $store->logo; } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } /** * 核销订单 */ public function actionClerkOrder() { $type = get_params('type'); $id = get_params('id'); $store_id = get_store_id(); $user_id = get_user_id(); // $current_user = User::findOne(['id' => $user_id, 'is_delete' => User::USER_NOT_DELETE, 'is_saas_clerk' => 1, 'store_id' => $store_id]); $current_user = MdStaff::findOne(['store_id' => $store_id, 'saas_user_id' => get_saas_user_id(), 'is_delete' => 0]); if (!$current_user) { return $this->asJson([ 'code' => 1, 'msg' => '您不是核销员,无法核销订单!' ]); } switch ($type) { case 'integral': $integral_order = SaasIntegralOrder::findOne(['id' => $id, 'is_delete' => 0]); if (!$integral_order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } if ($integral_order->is_clerk == 1) { return $this->asJson([ 'code' => 1, 'msg' => '订单已核销,无法再次核销' ]); } SaasIntegralOrder::updateAll(['is_clerk' => 1, 'clerk_id' => $user_id], ['store_id' => $store_id, 'id' => $id]); return $this->asJson([ 'code' => 0, 'msg' => '核销成功' ]); default: return $this->asJson([ 'code' => 1, 'msg' => 'fail' ]); } } /** * 删除订单 */ public function actionDeleteOrder() { $type = get_params('type'); $id = get_params('id'); $store_id = get_store_id(); switch ($type) { case 'scan': Order::updateAll(['is_delete' => 1], ['store_id' => $store_id, 'id' => $id]); return $this->asJson([ 'code' => 0, 'msg' => 'success' ]); case 'integral': SaasIntegralOrder::updateAll(['is_delete' => 1], ['store_id' => $store_id, 'id' => $id]); return $this->asJson([ 'code' => 0, 'msg' => 'success' ]); default: return $this->asJson([ 'code' => 1, 'msg' => 'fail' ]); } } /** * 订单详情 */ public function actionOrderDetail() { $type = get_params('type'); $id = get_params('id'); $order = []; switch ($type) { case 'scan': $scan_temp = Order::findOne(['id' => $id, 'is_delete' => 0]); $order['goods_name'] = '当面付'; $goods_id = OrderDetail::findOne(['order_id' => $scan_temp->id])->goods_id; $order['goods_pic'] = Goods::findOne($goods_id)->cover_pic; $order['cost'] = $scan_temp->pay_price; $order['order_no'] = $scan_temp->order_no; $order['coupon'] = Coupon::findOne(UserCoupon::findOne($scan_temp->user_coupon_id)->coupon_id); $order['status'] = $scan_temp->is_pay == 1 ? '已支付' : '未支付'; $order['created_at'] = $scan_temp->created_at; break; case 'integral': $integral_temp = SaasIntegralOrder::findOne(['id' => $id, 'is_delete' => 0]); $goods = Goods::findOne($integral_temp->goods_id); $order['goods_name'] = $goods->name; $order['goods_pic'] = $goods->cover_pic; $order['cost'] = $integral_temp->cost; $order['order_no'] = $integral_temp->order_no; $order['status'] = $integral_temp->is_clerk == 1 ? '已核销' : '待核销'; $order['created_at'] = $integral_temp->created_at; break; default: return $this->asJson([ 'code' => 1, 'msg' => 'fail' ]); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $order ]); } /** * 个人分账记录 * @return \yii\web\Response */ public function actionShareProfitRecord() { $page = get_params('page', 1); $limit = get_params('limit', 10); $user = get_user(); $query = SharingReceiver::find(); if (\Yii::$app->isSaas()) { $users = User::find()->where(['binding' => $user->binding])->select('wechat_open_id')->asArray()->all(); $users_open_id = array_column($users, 'wechat_open_id'); $query->where(['in', 'account', $users_open_id]); } else { $query->where(['store_id' => $user->store_id, 'account' => $user->wechat_open_id]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as $key => $value) { $tmp = []; $tmp['order_no'] = $value['order_no']; $tmp['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $tmp['amount'] = $value['amount']; $tmp['remark'] = $value['remark']; $tmp['pay_status'] = $value['is_pay'] == 0 ? '待分账' : ($value['is_pay'] == 1 ? '已分账' : '分账失败'); $list[$key] = $tmp; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } /** * 联盟佣金提现提交 */ public function actionCashCommit() { $amount = post_params('amount'); if ($amount < 0.01) { return $this->asJson([ 'code' => 1, 'msg' => '提现最小金额不能小于0.01元' ]); } $user = !empty(get_user()) ? get_user() : User::find()->where(['binding'=>get_saas_user()->mobile])->one(); $saas_user = SaasUser::findOne(['mobile' => $user->binding]); if ($saas_user->share_profit < $amount) { return $this->asJson([ 'code' => 1, 'msg' => '当前提现金额大于可提现联盟佣金' ]); } if (!$saas_user->platform_open_id) { return $this->asJson([ 'code' => 1, 'msg' => '请先绑定平台小程序openid' ]); } $t = \Yii::$app->db->beginTransaction(); $cash = new SaasProfitCash(); $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_SAAS_PROFIT_CASH); $cash->user_id = get_saas_user_id(); $cash->mobile = $user->binding; $cash->amount = $amount; $cash->status = SaasProfitCash::CASH_STATUS_WAIT; $cash->created_at = time(); if (!$cash->save()) { return $this->asJson([ 'code' => 1, 'msg' => $cash->errors[0] ]); } $cash->before_price = $saas_user->share_profit; $cash->after_price = ($saas_user->share_profit - $amount); $saas_user->share_profit = $saas_user->share_profit - $amount; $saas_user->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '提交成功,请等待审核' ]); } /** * 联盟佣金提现列表 */ public function actionCashList() { $page = get_params('page', 1); $limit = get_params('limit', 10); $user = get_user(); $query = SaasProfitCash::find()->where(['mobile' => !empty($user->binding) ? $user->binding : get_saas_user()->mobile]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset) ->asArray()->orderBy(['created_at' => SORT_DESC])->all(); foreach ($list as &$value) { $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $value['status_text'] = $value['status'] == 0 ? '待审核' : ($value['status'] == 1 ? '已通过' : '已拒绝'); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ] ]); } public function actionCheck() { $phone = get_params('phone'); if (empty($phone)) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误' ]); } $share_user = SaasUser::findOne(['mobile' => $phone]); if (!$share_user || empty($share_user->platform_open_id)) { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => 0 ]); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => 1 ]); } public function actionPlatformLogin() { $form = new PlatformLoginForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); return $this->asJson($form->login()); } public function actionSearchKeyword() { $keyword = Option::get('search_keyword', 0, 'saas', json_encode([])); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($keyword['value']), ]); } public function actionAddHistory() { $saas_user_id = get_saas_user_id(); if ($saas_user_id > 0) { $store_id = get_store_id(); $history = SaasHistory::find()->where(['user_id' => $saas_user_id, 'store_id' => $store_id])->one(); if ($history) { $history->updated_at = time(); $history->save(); } else { $history = new SaasHistory(); $history->user_id = $saas_user_id; $history->store_id = $store_id; $history->updated_at = time(); $history->save(); } } return $this->asJson([ 'code' => 0, 'msg' => '添加成功', ]); } public function actionGetHistory() { $page = get_params('page', 1); $limit = 10; $query = SaasHistory::find()->alias('sh') ->leftJoin(['s' => Store::tableName()], 'sh.store_id=s.id') ->select(['s.id', 's.name', 's.logo']); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $query->limit($limit)->offset($pagination->offset); $list = $query->orderBy(['sh.updated_at' => SORT_DESC])->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $list, ]); } public function actionOtherInfo() { $store_apply_banner = Option::get('store_apply_banner', 0, 'saas', '')['value']; $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value']; return $this->asJson([ 'code' => 0, 'data' => [ 'store_apply_banner' => $store_apply_banner ? Json::decode($store_apply_banner) : [], 'store_apply_agreement' => $admin_copyright ] ]); } /** * 获取信息 与ocr/info接口内容一致 * @return \yii\web\Response */ public function actionOcrInfo() { $type = post_params('type'); if (empty($type) || !in_array($type, OcrApi::$validType)) { return $this->asJson([ 'code' => 1, 'msg' => '类型参数错误' ]); } $side = post_params('side'); if (empty($side) && $type == OcrApi::TYPE_ID_CARD) { return $this->asJson([ 'code' => 1, 'msg' => '身份证参数有误' ]); } $url = post_params('url'); if (empty($url)) { return $this->asJson([ 'code' => 1, 'msg' => '图片地址为空' ]); } try { $ocr = new OcrApi(true); switch ($type) { case OcrApi::TYPE_LICENSE: $res = $ocr->getBusinessLicense($url); break; case OcrApi::TYPE_ID_CARD: $res = $ocr->getIDCard($url, $side); break; case OcrApi::TYPE_BANK: $res = $ocr->getBankCard($url); break; case OcrApi::TYPE_TEXT: $res = $ocr->getTextRecognition($url, 1); break; } if ($res['code'] == 0 && !empty($res['data'])) { return $this->asJson($res); } return $this->asJson([ 'code' => 1, 'msg' => '获取信息失败' ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } }