scenario = $form::SCENARIO_LIST; $form->attributes = $param; return $this->asJson($form->searchMd()); } /** * 门店列表 */ public function actionAuditList() { $param = get_params(); $form = new MdForm(); $form->attributes = $param; return $this->asJson($form->searchAudit()); } /** * 门店添加 */ public function actionAdd() { $form = new MdForm(); $form->scenario = $form::SCENARIO_ADD; $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->saveMd()); } /** * 门店编辑 */ public function actionDetail() { $id = get_md_id(); $md = Md::findOne($id); $md->password = ""; $md->cat_id = intval($md->cat_id) ?: null; $res = [ 'code' => 0, 'data' => $md ]; return $this->asJson($res); } /** * 门店编辑 */ public function actionEdit() { $param = post_params(); $form = new MdForm(); $form->scenario = $form::SCENARIO_EDIT; $form->attributes = $param; $form->store_id = get_store_id(); return $this->asJson($form->saveMd()); } /** * 删除门店 */ public function actionDel() { //主键id用key标识并进行获取 $param = get_params('key'); $form = new MdForm(); $form->scenario = $form::SCENARIO_DEL; $form->id = $param; return $this->asJson($form->delMd()); } /** * 审核 */ public function actionAudit() { $param = post_params(); $form = new MdForm(); $form->scenario = $form::SCENARIO_AUDIT; $form->attributes = $param; return $this->asJson($form->auditMd()); } /** * 审核门店 * @return \yii\web\Response */ public function actionBatchAudit() { $id = post_params('id'); $status = post_params('shop_audit'); if (!in_array($status, [Md::SHOP_AUDIT_NO, Md::SHOP_AUDIT_YES])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } if (empty($id) || !is_array($id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } $t = \Yii::$app->db->beginTransaction(); Md::updateAll(['shop_audit' => $status, 'audit_time' => time()], ['in', 'id', $id]); if ($status == 1) { foreach ($id as $value) { $md = Md::findOne($value); if ($md->user_id > 0) { $md->manager = $md->user_id; if (!$md->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } $saas_user = SaasUser::findOne($md->user_id); $md_staff = MdStaff::findOne(['saas_user_id' => $md->user_id, 'is_delete' => 0, 'store_id' => get_store_id()]); if (!$md_staff) { $md_staff = new MdStaff(); $md_staff->saas_user_id = $md->user_id; $md_staff->is_manager = 1; $md_staff->store_id = get_store_id(); $md_staff->md_id = $md->id; $md_staff->name = $saas_user->name; $md_staff->mobile = $saas_user->mobile; if (!$md_staff->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $md_staff->errors[0] ]); } //兼容老版本 $user_name = $md->user_name ?: $md->mobile; $exist_admin = Admin::findOne(['type' => 'md', 'type_id' => $md->id, 'username' => $user_name, 'store_id' => get_store_id()]); if ($exist_admin) { $exist_admin->is_delete = 1; if (!$exist_admin->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $exist_admin->errors[0] ]); } } $admin = Admin::find()->where(['username' => $user_name, 'is_delete' => 0])->one(); if ($admin) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '保存失败,管理员账户已经存在' ]); } // 自动创建admin账号 $admin = new Admin(); $admin->store_id = get_store_id(); $admin->access_token = \Yii::$app->security->generateRandomString(); $admin->username = $md->user_name; $admin->password = $md->password; $admin->mobile = $md->mobile; $admin->avatar = $saas_user->avatar; $admin->name = $md->name; $admin->type = 'md'; $admin->type_id = $md->id; if (!$admin->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $admin->errors[0] ]); } } } } // 消息队列处理批量下架门店商品 // queue_push(new BatchDownGoodsJob(['ids' => $id, 'store_id' => get_store_id()])); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '审核成功' ]); } /** * 手动更新平台规格数据 * @return \yii\web\Response */ public function actionSetAttr() { $goods_id = post_params('goods_id'); // $md_id = get_md_id(); if (!is_array($goods_id) || empty($goods_id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } try { $count = 0; foreach ($goods_id as $id) { $md_goods = MdGoods::find()->where(['goods_id' => $id])->all(); if (empty($md_goods)) { continue; } $goods = Goods::findOne($id); foreach ($md_goods as $key => $value) { $value->attr = $goods->attr; $value->goods_num = $goods->goods_num; $value->price = $goods->price; $value->status = 0; if ($value->save()) { $count++; } } } return $this->asJson([ 'code' => 0, 'msg' => '成功同步' . $count . '条门店商品数据', ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 0, 'msg' => '出现错误', ]); } } /** * 门店订单转单至平台 */ public function actionTransOrder() { $order_id = post_params('id'); $order = Order::find()->where(['store_id' => get_store_id(), 'id' => $order_id, 'is_delete' => 0])->andWhere( ['<', 'trade_status', Order::ORDER_FLOW_CANCEL] )->one(); if (!$order) { return $this->asJson([ 'code' => 1, 'msg' => '转单数据有误' ]); } $order->is_trans = 1; if ($order->save()) { return $this->asJson([ 'code' => 0, 'msg' => '转单成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $order->errors[0] ]); } } /** * 更换店长 * @return \yii\web\Response */ public function actionManager() { $md_id = post_params('md_id'); $saas_user_id = post_params('saas_user_id'); if (empty($md_id) || empty($saas_user_id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误' ]); } $md = Md::findOne($md_id); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '门店不存在' ]); } $staff = MdStaff::findOne(['store_id' => get_store_id(), 'saas_user_id' => $saas_user_id, 'is_delete' => 0]); $staff_1 = MdStaff::findOne(['store_id' => get_store_id(), 'md_id' => $md_id, 'saas_user_id' => $saas_user_id, 'is_delete' => 0]); if ($staff && !$staff_1) { return $this->asJson([ 'code' => 1, 'msg' => '该员工已在其他门店下,请重新选择' ]); } $t = \Yii::$app->db->beginTransaction(); $old_manager = MdStaff::findOne(['store_id' => get_store_id(), 'md_id' => $md_id, 'is_manager' => 1, 'is_delete' => 0]); if ($old_manager) { $old_manager->is_manager = 0; if (!$old_manager->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $old_manager->errors[0] ]); } } if (!$staff_1) { $saas_user = SaasUser::findOne($saas_user_id); $md_staff = new MdStaff(); $md_staff->store_id = get_store_id(); $md_staff->md_id = $md_id; $md_staff->saas_user_id = $saas_user_id; $md_staff->name = $saas_user->name; $md_staff->mobile = $saas_user->mobile; $md_staff->is_manager = 1; if (!$md_staff->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $md_staff->errors[0] ]); } } else { $staff_1->is_manager = 1; if (!$staff_1->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $staff_1->errors[0] ]); } } $md->manager = $saas_user_id; $md->user_id = $saas_user_id; if (!$md->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'data' => $md->errors[0] ]); } $t->commit(); return $this->asJson([ 'code' => 0, 'data' => '操作成功' ]); } /** * 批量操作 * @return \yii\web\Response */ public function actionBatch() { $id = post_params('id'); $status = post_params('status'); if (!is_array($id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数不正确' ]); } // 这里需要判断是否是独立运营门店 如果是独立运营门店 将独立运营门店修改为非独立的 并保留门店员工数据 如果是非独立运营门店执行删除 要删除门店员工 $md_list = Md::find()->where(['in', 'id', $id])->all(); foreach ($md_list as $md){ if($md->is_single == 1){ $md->is_single = 0; $md->save(); }else{ $md->is_delete = 1; if($md->save()){ // 删除门店员工 MdStaff::updateAll(['is_delete' => 1], ['id'=>$md->id]); } } } return $this->asJson([ 'code' => 0, 'msg' => '更新成功' ]); } public function actionStaff() { $name = get_params('name'); $mobile = get_params('mobile'); $start_time = get_params('start_time'); $end_time = get_params('end_time'); $md_id = get_params('md_id'); $store_id = get_store_id(); $is_single = get_params('is_single');// 这里不能给默认值,给了的话会影响门店后台的员工列表请求 if ($is_single == null) { $md = Md::findOne($md_id); if ($md) { $is_single = $md->is_single; } } $query = MdStaff::find()->alias('ms')->leftJoin(['md' => Md::tableName()], 'md.id=ms.md_id')->where(['ms.is_delete' => 0])->orderBy("ms.created_at desc, ms.updated_at desc"); if ($md_id !== null) { if ($md_id <= 0) { $query->andWhere(['AND', ['ms.md_id' => [0, -1]], ['IS', 'md.id', NULL]]); } else { $query->andWhere(['ms.md_id' => $md_id, 'md.is_delete' => 0, 'md.is_single' =>$is_single]); } }else{ // 商城后台查询员工的时候 要根据$is_single取独立运营门店 或者 非独立运营门店的店员 $query->andWhere( ['md.is_single' =>$is_single]); } if ($store_id > 0) { $query->andWhere(['ms.store_id' => $store_id]); } if ($name) { $query->andWhere(['like', 'ms.name', $name]); } if ($mobile) { $query->andWhere(['like', 'ms.mobile', $mobile]); } if ($start_time) { $query->andWhere(['>=', 'ms.created_at', strtotime($start_time)]); } if ($end_time) { $query->andWhere(['<=', 'ms.created_at', strtotime($end_time)]); } $list = pagination_make($query); foreach ($list['list'] as &$val) { $saas_user = SaasUser::findOne($val['saas_user_id']); $user = User::findOne(['store_id' => get_store_id(),'binding' => $saas_user->mobile]); $val['avatar'] = $user->avatar_url; $val['md_name'] = Md::findOne($val['md_id'])->name; if ($val['md_id'] <= 0) { $val['md_name'] = Store::findOne($val['store_id'])->name; } $val['nickname'] = $user->nickname; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'] ] ]); } public function actionStaffAdd() { $store_id = get_store_id(); $md_id = get_md_id(); $name = post_params('name'); $mobile = post_params('mobile'); $saas_user_id = post_params('saas_user_id'); if (empty($name) || empty($mobile) || empty($saas_user_id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误' ]); } $user = User::findOne($saas_user_id); if (!$user) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在' ]); } $saas_user = SaasUser::findOne(['mobile' => $user->binding]); if (!$saas_user) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在' ]); } $staff = MdStaff::findOne(['store_id' => $store_id, 'saas_user_id' => $saas_user->id, 'is_delete' => 0]); if ($staff) { return $this->asJson([ 'code' => 1, 'msg' => '该员工已在其他门店下,请重新绑定' ]); } if ($md_id <= 0) { $staff = MdStaff::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]); if ($staff) { return $this->asJson([ 'code' => 1, 'msg' => '该用户已在其他店铺下,请重新绑定' ]); } } $md_staff = new MdStaff(); $md_staff->store_id = $store_id; $md_staff->md_id = $md_id; $md_staff->saas_user_id = $saas_user->id; $md_staff->name = $name; $md_staff->mobile = $mobile; if (!$md_staff->save()) { return $this->asJson([ 'code' => 1, 'msg' => $md_staff->errors[0] ]); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } /** * 更新状态 * @return \yii\web\Response */ public function actionStaffStatus() { $id = post_params('id'); $type = post_params('type'); $status = post_params('status'); if (empty($id) || !is_array($id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误' ]); } if (!in_array($status, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '状态参数有误' ]); } if ($type == 'is_disable') { MdStaff::updateAll(['is_disable' => $status], ['in', 'id', $id]); } if ($type == 'is_delete') { MdStaff::updateAll(['is_delete' => $status], ['in', 'id', $id]); } return $this->asJson([ 'code' => 0, 'msg' => '更新成功' ]); } public function actionSelectList() { $is_single = get_params('is_single', -1); $query = Md::find()->where(['is_delete' => 0, 'shop_audit' => 1, 'store_id' => get_store_id()])->select('id, name'); if($is_single != -1){ $query->andWhere(['is_single' => $is_single]); } $list = $query->asArray()->all(); return $this->asJson( ['code' => 0, 'data' => $list] ); } public function actionProfit() { $export = get_params('export'); $order_no = get_params('order_no'); $md_name = get_params('md_name'); $is_send = get_params('is_send'); $start_time = get_params('start_time'); $end_time = get_params('end_time'); $md_id = get_md_id(); $query = MdProfit::find()->alias('mp')->leftJoin(['md' => Md::tableName()], 'md.id=mp.md_id') ->leftJoin(['o' => Order::tableName()], 'o.id=mp.order_id') ->where(['mp.store_id' => get_store_id()]) ->select('mp.*, md.is_single, md.cover_url, o.order_no, o.user_id')->orderBy("mp.created_at desc, mp.updated_at desc"); if ($md_id) { $query->andWhere(['mp.md_id' => $md_id]); } if (in_array($is_send, [0, 1])) { $query->andWhere(['mp.is_send' => $is_send]); } if ($order_no) { $query->andWhere(['like', 'o.order_no', $order_no]); } if ($md_name) { $query->andWhere(['like', 'md.name', $md_name]); } if ($start_time) { $query->andWhere(['>=', 'mp.created_at', strtotime($start_time)]); } if ($end_time) { $query->andWhere(['<=', 'mp.created_at', strtotime($end_time)]); } $list = pagination_make($query); foreach ($list['list'] as &$val) { $val['md_name'] = Md::findOne($val['md_id'])->name; if ($val['saas_user_id']) { $val['user_name'] = SaasUser::findOne($val['saas_user_id'])->name; } else { $val['user_name'] = SaasUser::findOne(['mobile' => User::findOne($val['user_id'])->binding])->name; } } if($export){ return $this->exportProfit($list['list']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'] ] ]); } private function exportProfit($list) { $rows = [[ 'ID', '门店名称', '昵称', '下单时间', '订单号', '销售佣金(元)', '核销佣金(元)', '利润佣金(元)', '总佣金(元)', '操作时间', '佣金状态', ]]; foreach($list as $item){ $r = [ $item['id'], $item['md_name'], $item['user_name'], date('Y-m-d H:i:s', $item['created_at']), $item['order_no'], $item['pay_profit'], $item['clerk_profit'], $item['sale_profit'], $item['total_profit'], $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-', $item['is_send'] == 0 ? '未到账' : '已到账', ]; $rows[] = $r; } $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow() ->addRows($rows)->toBrowser(); } public function actionProfitData() { $id = input_params('id'); $store_id = get_store_id(); $query = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->orderBy("id desc"); $queryCount = clone $query; if ($id) { $query->andWhere(['id' => $id]); } $query->select('id, is_single, name, cover_url, total_profit, cash_profit'); $list = pagination_make($query); foreach($list['list'] as &$item){ $item['mdCashSum'] = floor_num(Cash::find()->where(['is_delete' => Cash::IS_DELETE_NO, 'md_id' => $item['id'], 'status' => 2])->andWhere(['cash_type' => 2])->sum('price')); $item['mdProfitWait'] = floor_num(MdProfit::find()->where(['md_id' => $item['id'], 'is_send' => 0])->sum('total_profit')); } if($list['pageNo'] == 1){ $count = []; $count['mdCount'] = (int)$queryCount->count(); $count['mdCashPriceSum'] = floor_num($queryCount->sum('cash_profit')); $count['mdCashSum'] = floor_num(Cash::find()->where(['is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id, 'status' => 2])->andWhere(['cash_type' => 2])->sum('price')); $count['mdProfitWait'] = floor_num(MdProfit::find()->where(['store_id' => $store_id, 'is_send' => 0])->sum('total_profit')); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $list, 'count' => $count, ]); } public function actionOtherInfo() { // 获取门店设置 $form = new MdSettingForm(); $form->store_id = get_store_id(); $result = $form->getSetting(); return $this->asJson([ 'code' => 0, 'data' => $result ]); } public function actionSubmitOtherInfo() { // 保存门店设置 $form = new MdSettingForm(); $form->store_id = get_store_id(); $form->scenario = 'save'; $form->attributes = all_params(); $result = $form->saveSetting(); return $this->asJson($result); } public function actionCashList() { $export = get_params('export'); $md_id = get_params('md_id'); $start_time = get_params('start_time'); $end_time = get_params('end_time'); $status = get_params('status'); $type = get_params('type'); $store_id = get_store_id(); $query = Cash::find()->alias('c') ->leftJoin(['md' => Md::tableName()], 'md.id=c.md_id') ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $store_id]) ->andWhere(['c.cash_type' => 2]); if ($start_time) { $query->andWhere(['>=', 'c.created_at', strtotime($start_time)]); } if ($end_time) { $query->andWhere(['<=', 'c.created_at', strtotime($end_time)]); } if ($type != -1 && isset($type)) { $query->andWhere(['c.type' => $type]); } if ($md_id) { $query->andWhere(['c.md_id' => $md_id]); } if ($status == Cash::STATUS_APPLY) { //待审核 $query->andWhere(['c.status' => Cash::STATUS_APPLY]); } if ($status == Cash::STATUS_CONFIRM) { // 待打款 $query->andWhere(['c.status' => Cash::STATUS_CONFIRM]); } if ($status == Cash::STATUS_GIVEN) { // 已打款 $query->andWhere(['in', 'c.status', [Cash::STATUS_GIVEN, Cash::STATUS_RECHARGE]]); } if ($status == Cash::STATUS_REFUSE) { // 已拒绝 $query->andWhere(['c.status' => Cash::STATUS_REFUSE]); } $query->distinct()->orderBy('c.status ASC,c.created_at DESC')->select([ 'c.*','md.name md_name', 'md.cover_url', 'md.is_single' ]); $pagination = pagination_make($query); $list = $pagination['list']; foreach($list as &$value){ $value['service_money'] = $value['service_charge'] * $value['price'] / 100; $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : ''; $value['money'] = Cash::getServiceMoney($value); $value['status_name'] = Cash::getCashStatusName($value); $saas_user = SaasUser::findOne(['mobile' => $value['binding']]); $value['avatar_url'] = !empty($saas_user['avatar']) ? $saas_user['avatar'] : $value['avatar_url']; $value['card_no'] = ''; if (intval($value['type']) === Cash::TYPE_BANK) { if ($saas_user->withdraw_method) { $withdraw_method = json_decode($saas_user->withdraw_method, true); if (!empty($withdraw_method)) { foreach ($withdraw_method as $method_item) { if ($method_item['type'] === 'bank_card') { $value['card_no'] = $method_item['card_no']; } } } } } $value['type_text'] = Cash::getTypeName($value['type']) . "提现"; } if($export){ return $this->exportCashList($list); } $md = Md::findOne($md_id); $profit = [ 'cash_profit' => '0.00', 'profit' => '0.00', 'total_profit' => '0.00', ]; if ($md) { //可提现金额 $profit['cash_profit'] = $md->cash_profit ?: '0.00'; //已提现金额 $saas_user_id = MdStaff::findOne(['store_id' => $store_id, 'md_id' => $md_id, 'is_manager' => 1])->saas_user_id; $profit['profit'] = Cash::find()->where(['user_id' => $saas_user_id, 'status' => [0, 1, 2], 'md_id' => $md_id, 'cash_type' => 2])->sum('price') ?: '0.00'; //累计金额 $profit['total_profit'] = $md->total_profit ?: '0.00'; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'profit' => $profit, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'] ], ]); } private function exportCashList($list) { $rows = [[ 'ID', '提现方式', '提现金额(元)', '申请时间', '审批时间', '状态', ]]; foreach($list as $item){ $r = [ $item['id'], $item['type'] == 0 ? '微信转账' : $item['type'] == 1 ? '支付宝转账' : '银行卡转账', $item['price'], date('Y-m-d H:i:s', $item['created_at']), $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-', $item['status'] == 0 ? '未处理' : $item['status'] == 1 ? '待打款' : $item['status'] == 2 ? '已完成' : $item['status'] == 3 ? '已拒绝' : '', ]; $rows[] = $r; } $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow() ->addRows($rows)->toBrowser(); } /** * 提现申请审核 * @return \yii\web\Response */ public function actionCashApply() { $id = post_params('id'); $status = post_params('status'); $store_id = get_store_id(); if (empty($id) || !is_array($id)) { return $this->asJson([ 'code' => 1, 'msg' => '数据格式错误' ]); } $t = \Yii::$app->db->beginTransaction(); foreach ($id as $value) { $cash = Cash::findOne(['id' => $value, 'is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id]); if (!$cash) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if (\in_array($cash->status, [1, 3])) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作失败,请刷新重试' ]); } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } \Yii::$app->cache->set('md_cash_cache_' . $value, $cash->order_no); if (!in_array($status, [1, 3])) { \Yii::$app->cache->set('md_cash_cache_' . $value, false); $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '提现记录ID: ' . $value . '已审核,请刷新重试' ]); } $cash->status = $status; if ($status == Cash::STATUS_REFUSE) { $md = Md::findOne($cash->md_id); $md->updateCounters(['cash_profit' => $cash->price]); } if (!$cash->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '网络异常,请刷新重试' ]); } } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '审核成功' ]); } public function actionCashConfirm() { $id = post_params('id'); $status = post_params('status'); $store_id = get_store_id(); $store = Store::findOne($store_id); $cash = Cash::findOne([ 'id' => $id, 'is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id ]); if (!$cash) { return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if ($status == Cash::STATUS_GIVEN) { if($store->is_platform_transfers == 1){ $store_wechat_cash = json_decode(Option::get('store_wechat_cash', $store_id, 'store')['value'], true); $val = 0; foreach ((array)$store_wechat_cash as $value) { if (!empty($value)) { $val = 1; break; } } if(!$val){ return $this->asJson([ 'code' => 1, 'msg' => '未配置平台微信提现设置' ]); } } } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } if ($cash->status != 1) { return $this->asJson([ 'code' => 1, 'msg' => '操作错误,请刷新重试' ]); } $res = []; // $price = $cash->price; $price = Cash::getServiceMoney($cash); $servePrice = ($cash->price * ($cash->service_charge / 100)); if ($store->store_balance < $price && $store->is_platform_transfers == 1) { return $this->asJson([ 'code' => 1, 'msg' => '店铺剩余提现余额不足' ]); } $wechat_type = 1; $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if($store->is_platform_transfers == 1){ $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; $wechat_type = 0; } $t = \Yii::$app->db->beginTransaction(); if ($status == Cash::STATUS_GIVEN) { //微信自动打款 $cash->status = Cash::STATUS_GIVEN; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_WX; $cash->wx_cash_status = -1; $user = User::findOne(['id' => $cash->user_id]); $data = [ 'partner_trade_no' => $cash->order_no, 'openid' => $user->wechat_open_id, 'check_name' => 'NO_CHECK', 'amount' => $price * 100, 'desc' => '转账', 'user_name' => $cash->name ]; if ((int)$cash->type === 0) { if (\Yii::$app->prod_is_dandianpu() && !\app\models\Store::hasIncoming($store_id)) { //商城是否进件 //商城余额是否充足 $storeMoney = \app\models\StoreCash::getMaxCash($store); if($storeMoney < $price){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作错误,商城余额不足! 当前余额:¥' . $storeMoney ]); } //扣除商城余额 $subMoney = \app\models\Store::subMoney($store, $price); if(!$subMoney){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '网络异常,subMoney失败1', ]); } $cash->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { if (\Yii::$app->prod_is_duli()) { $WechatConfig = WechatConfig::findOne(['store_id' => get_store_id()]); if (empty($WechatConfig->mch_id) || empty($WechatConfig->pay_key) || empty($WechatConfig->app_id)|| empty($WechatConfig->cert_pem)|| empty($WechatConfig->key_pem)) { return $this->asJson([ 'code' => 1, 'msg' => "后台参数配置错误,请检查参数后重试" ]); } } } if ($wechat_type == 0) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); $before = $store->store_balance; $real_price = $cashExt ? $cashExt->real_price : $price; $store->updateCounters(['store_balance' => -$real_price, 'price' => -$real_price, 'store_withdrawn_cash' => $real_price]); $after = $store->store_balance; $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice; $cashExtPrice = $cashExt ? $cashExt->price : $cash->price; $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price; StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type); } $wechat = \Yii::$app->controller->wechatPay; // $res = $wechat->transfer->toBalance($data); $res = (new \app\utils\WechatMerchant\WxV3($wechat))->transferBatches(get_store_id(), $data); //判断是否使用新版本转账 增加转账标识 $wechat_cash = json_decode($wechat_cash, true); if (intval($wechat_cash['is_open']) === 2) { if (!$res['code']) { $cash->is_platform_transfers = intval($store->is_platform_transfers); $cash->wx_cash_type = Cash::WX_CASH_TYPE_NEW; $cash->wx_cash_state = $res['data']['state']; $cash->wx_cash_result_info = json_encode($res['data'], JSON_UNESCAPED_UNICODE); $cash->save(); } } NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '微信自动打款', ($cash->price - $price)); } elseif ((int)$cash->type === 1) { $order = (object)[ 'store_id' => $cash->store_id, 'order_no' => $cash->order_no, 'pay_price' => sprintf("%.2f", $price), 'name' => $cash->name ]; $result = Alipay::transfer($order, $cash->mobile); if (isset($result['code']) && $result['code'] == 1) { if (strpos($result['msg'], 'aop.invalid-app-auth-token-no-api')) { $result['msg'] = '接口未授权,请前往支付宝开放平台查询是否开通产品或授权支付宝转账产品'; } if (strpos($result['msg'], 'PAYEE_NOT_EXIST')) { $result['msg'] = '收款账号不存在或姓名有误,建议核实账号和姓名是否准确'; } if (strpos($result['msg'], 'BALANCE_IS_NOT_ENOUGH')) { $result['msg'] = '商户余额不足'; } return $this->asJson($result); } else { // TODO 扣除店铺提现金额 if ($wechat_type == 0) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); $before = $store->store_balance; $real_price = $cashExt ? $cashExt->real_price : $price; $store->updateCounters(['store_balance' => -$real_price, 'price' => -$real_price, 'store_withdrawn_cash' => $real_price]); $after = $store->store_balance; $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice; $cashExtPrice = $cashExt ? $cashExt->price : $cash->price; $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price; StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type); } } $cash->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); }elseif ((int)$cash->type === 4) { $user = User::findOne($cash->user_id); $saas = SaasUser::findOne(['mobile' => $user->binding]); $lg_info = Lg::find()->where(['user_id'=>$saas->id,'status'=>1,'is_delete'=>0])->one(); $lgApi = new LgApi($cash->store_id); //灵工提现 $post_data = [ 'store_id' => $cash->store_id, 'outTradeNo' => $cash->order_no,//唯一批次号 'accNo' => bcmul($price,100), 'amt' => bcmul($price,100), 'name' => $lg_info->name, 'certCard' => $lg_info->cert_card//身份证号 ]; $result = $lgApi->FlexiblePay($post_data); if (isset($result['status']) && $result['status'] == 999) { return $this->asJson($result); } $cash->status = 6;//灵工待打款 $cash->save(); $t->commit(); //灵工提现接口调用后消息队列查询状态 \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$store_id,'type'=>0,'retry' => 5]), 60); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } } elseif ($status == Cash::STATUS_HAND) { //手动打款 // TODO 扣除店铺提现金额 if ($wechat_type == 0) { $before = $store->store_balance; $store->updateCounters(['store_balance' => -$price, 'price' => -$price, 'store_withdrawn_cash' => $price]); $after = $store->store_balance; StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHOP, $price, " ID{$id}:用户提现{$cash->price}元,扣除手续费{$servePrice}元,提现实际扣除{$price}元", $before, $after, $wechat_type); } $cash->status = Cash::STATUS_GIVEN; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_HAND; $res['result_code'] = "SUCCESS"; // NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '手动打款', ($cash->price - $price)); } if (isset($res['result_code']) && $res['result_code'] == 'SUCCESS') { $cash->save(); if ($cash->cash_type == 2){ //灵工提现接口调用后消息队列查询状态 \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$store_id,'type'=>2,'retry' => 5]), 60); } if (intval($cash->type) === Cash::TYPE_RECHARGE) { AccountLog::saveLog($cash->user_id, $price, 2, 1, 0, 0, '佣金提现打款'); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => !empty($res['err_code_des']) ? $res['err_code_des'] : '请稍后重试', 'data' => $res ]); } } public function actionCashSubmit() { $price = post_params('cash'); $type = post_params('type'); $name = post_params('name', ''); $account = post_params('account', ''); $bank = post_params('bank', ''); if (!$price || !in_array($type, [0, 1, 2])) { return $this->asJson([ 'code' => 1, 'msg' => '参数非法', ]); } if (empty($name) || empty($account)) { return $this->asJson([ 'code' => 1, 'msg' => '账户和姓名不能为空', ]); } if ($type == 2 && empty($bank)) { return $this->asJson([ 'code' => 1, 'msg' => '银行账号开户行不能为空', ]); } $store_id = get_store_id(); $md_id = get_md_id(); $saas_user_id = MdStaff::findOne(['store_id' => $store_id, 'md_id' => $md_id, 'is_manager' => 1])->saas_user_id; $md = Md::findOne($md_id); if ($price > $md->cash_profit) { return $this->asJson([ 'code' => 1, 'msg' => '当前大于可提现金额' ]); } $exit = Cash::find()->andWhere(['=', 'status', 0])->andWhere(['user_id' => $saas_user_id, 'store_id' => $store_id, 'cash_type' => Cash::IS_CASH_TYPE_MD])->exists(); if ($exit) { // return $this->asJson([ // 'code' => 1, // 'msg' => '尚有未完成的提现申请' // ]); } $saasUser = SaasUser::findOne($saas_user_id); $user = User::find()->where(['store_id' => $store_id,'binding' => $saasUser->mobile,'is_delete' => 0])->one(); if(empty($user)){ return $this->asJson([ 'code' => 1, 'msg' => '提现用户数据不能为空' ]); } $t = \Yii::$app->db->beginTransaction(); $cash = new Cash(); $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH); $cash->is_delete = 0; $cash->status = 0; $cash->md_id = $md->id; $cash->price = $price; $cash->created_at = time(); $cash->user_id = $user->id; $cash->store_id = $store_id; $cash->type = $type; $cash->name = $name; $cash->mobile = $account; $cash->bank_name = $bank; $cash->pay_time = 0; $cash->service_charge = 0; $cash->cash_type = Cash::IS_CASH_TYPE_MD; if ($cash->save()) { $md->updateCounters(['cash_profit' => -$price]); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '申请成功' ]); } else { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '网络异常' ]); } } public function actionClerkOrderList() { $export = get_params('export'); $md_id = get_params('md_id'); $start_time = get_params('start_time'); $end_time = get_params('end_time'); $status = get_params('status'); $order_no = get_params('order_no'); $name = get_params('name'); $store_id = get_store_id(); $query = MdProfit::find()->alias('mp')->where(['mp.is_clerk' => 1, 'mp.store_id' => $store_id]) ->leftJoin(['ms' => MdStaff::tableName()], 'ms.id=mp.clerk_id') ->leftJoin(['o' => Order::tableName()], 'o.id=mp.order_id'); if ($start_time) { $query->andWhere(['>=', 'mp.created_at', strtotime($start_time)]); } if ($order_no) { $query->andWhere(['like', 'o.order_no', $order_no]); } if ($name) { $query->andWhere(['like', 'ms.name', $name]); } if ($end_time) { $query->andWhere(['<=', 'mp.created_at', strtotime($end_time)]); } if ($md_id) { $query->andWhere(['mp.md_id' => $md_id]); } if ($status != -1) { $query->andWhere(['mp.is_send' => $status]); } $query->orderBy('mp.created_at desc, mp.updated_at desc')->select('mp.*, ms.name, o.order_no, o.pay_price'); $pagination = pagination_make($query); $list = $pagination['list']; foreach ($list as &$value) { $value['goods_list'] = OrderDetail::find()->where(['order_id' => $value['order_id']])->select('goods_name, num, attr, pic, total_price')->asArray()->all(); } if($export){ return $this->exportClerkOrderList($list); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'] ], 'q' => $query->createCommand()->getRawSql(), ]); } private function exportClerkOrderList($list) { $rows = [[ 'ID', '订单编号', '产品名称', '规格', '单价(元)', '数量', '订单金额(元)', '核销员工', '下单时间', '核销时间', '订单状态', ]]; foreach($list as $item){ $r = [ $item['id'], $item['order_no'], $item['goods_list'][0]['goods_name'], implode(',', array_column(json_decode($item['goods_list'][0]['attr'], true), 'attr_name')), $item['goods_list'][0]['total_price'], $item['goods_list'][0]['num'], $item['pay_price'], $item['name'], date('Y-m-d H:i:s', $item['created_at']), $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-', $item['is_send'] == 0 ? '待核销':'已核销', ]; $rows[] = $r; if(count($item['goods_list']) > 1){ foreach($item['goods_list'] as $i => $goods){ if($i == 0) continue; $r = [ '', $item['goods_list'][$i]['goods_name'], implode(',', array_column(json_decode($item['goods_list'][$i]['attr'], true), 'attr_name')), $item['goods_list'][$i]['total_price'], $item['goods_list'][$i]['num'], ]; $rows[] = $r; } } } $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow() ->addRows($rows)->toBrowser(); } /** * 门店团购活动列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/20 10:02 */ public function actionGroupActivities() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); return $this->asJson($form->list()); } /** * 门店团购活动详情 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/20 10:02 */ public function actionGetGroupActivitiesItem() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); $form->id = get_params('id'); return $this->asJson($form->item()); } /** * 设置门店团购活动 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/20 10:02 */ public function actionSaveGroupActivitiesItem() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); $form->scenario = 'create'; $form->attributes = all_params(); return $this->asJson($form->createItem()); } /** * 删除门店团购活动 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/20 10:47 */ public function actionDelGroupActivitiesItem() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); $form->ids = get_params('ids'); $form->scenario = 'del'; return $this->asJson($form->del()); } public function actionGetQrcodeSetting() { //兼容联盟 $is_saas = get_params('is_saas',0); if($is_saas){ $store_id = -1; }else{ $store_id = get_store_id(); } $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MD]); // \Yii::error($qrcode->font); $color = Color::find()->select('id, color')->andWhere(['is_delete' => 0])->asArray()->all(); $font_position = json_decode($qrcode->font_position, true); $qrcode_position = json_decode($qrcode->qrcode_position, true); $avatar_position = json_decode($qrcode->avatar_position, true); $avatar_size = json_decode($qrcode->avatar_size, true); $qrcode_size = json_decode($qrcode->qrcode_size, true); $font_size = json_decode($qrcode->font, true); // \Yii::error($font_size); $first = Color::findOne(['color' => $font_size['color']]); $res = [ 'qrcode_bg' => $qrcode->qrcode_bg ?: \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/2_1.png', 'qrcode_pic' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/1.png', 'avatar' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png', 'qrcode' => $qrcode, 'color' => $color, 'first' => $first->id, 'font_c' => Json::decode($qrcode->font, true)['color'] ? Json::decode($qrcode->font, true)['color'] : ($first->color ?: "#000"), 'avatar_w' => $avatar_size['w'] ?: '63', 'avatar_x' => $avatar_position['x'] ?: '50', 'avatar_y' => $avatar_position['y'] ?: '160', 'qrcode_w' => $qrcode_size['w'] ?: '169', 'qrcode_c' => empty($qrcode_size['c']) ? 1 : (($qrcode_size['c'] == "true") ? 1 : 0), 'qrcode_x' => $qrcode_position['x'] ?: '65', 'qrcode_y' => $qrcode_position['y'] ?: '240', 'font_x' => $font_position['x'] ?: '124', 'font_y' => $font_position['y'] ?: '180', 'font_w' => $font_size['size'] ?: '20', ]; return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]); } /** * 设置门店海报 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/25 10:36 */ public function actionSetQrcodeSetting() { $store_id = get_store_id(); //兼容联盟 $is_saas = post_params('is_saas',0); if($is_saas){ $store_id = -1; } $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MD]); if (!$qrcode) { $qrcode = new Qrcode(); } $form = new QrcodeForm(); $form->attributes = post_params(); $form->store_id = $store_id; $form->qrcode = $qrcode; $form->type = Qrcode::TYPE_MD; return $this->asJson($form->save()); } /** * 司机列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/22 15:57 */ public function actionDriverList() { $form = new MdGroupDriverForm(); $form->store_id = get_store_id(); $form->attributes = all_params(); return $this->asJson($form->getList()); } /** * 新增编辑司机 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/22 15:57 */ public function actionDriverSave() { $form = new MdGroupDriverForm(); $form->scenario = 'save'; $form->store_id = get_store_id(); $form->attributes = all_params(); return $this->asJson($form->createItem()); } /** * 删除司机 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/22 16:02 */ public function actionDriverDel() { $form = new MdGroupDriverForm(); $form->scenario = 'del'; $form->store_id = get_store_id(); $form->id = get_params('id'); return $this->asJson($form->delItem()); } /** * diy装修获取活动列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/25 11:47 */ public function actionGetActivities() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); return $this->asJson($form->diyGetActivitiesList()); } /** * diy获取指定活动商品列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/25 11:47 */ public function actionGetActivityGoodsList() { $form = new MdGroupActivitiesForm(); $form->store_id = get_store_id(); $form->id = get_params('id'); return $this->asJson($form->getGoodsListByActivity()); } /** * 生成备货单操作 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/27 11:07 */ public function actionCreateInventory() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->attributes = all_params(); return $this->asJson($form->handleInventory()); } /** * 备货单列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/27 11:29 */ public function actionInventoryList() { $form = new InventoryForm(); $form->store_id = get_store_id(); return $this->asJson($form->getInventoryList()); } /** * 获取备货单详情 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/27 11:29 */ public function actionInventoryDetail() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->id = get_params('id');// 备货单ID return $this->asJson($form->getInventoryDetail()); } /** * 分拣单列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/27 11:29 */ public function actionSortingList() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->md_id = get_params('md_id',0);// 根据门店搜索分拣单 $form->inventory_id = get_params('inventory_id',0);// 备货单iD $form->status = get_params('status',-1); $form->md_id = get_params('md_id',0); return $this->asJson($form->getSortingList()); } /** * 获取分拣单详情 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/27 11:29 */ public function actionSortingDetail() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->id = get_params('id');// 分拣单ID return $this->asJson($form->getSortingDetail()); } /** * 获取备货单的所有配送单 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/28 15:11 */ public function actionSortingDetailAll() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->id = get_params('id');// 备货单ID return $this->asJson($form->getSortingDetailAll()); } /** * 获取可用司机列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/28 15:12 */ public function actionGetDriverList() { $form = new MdGroupDriverForm(); $form->store_id = get_store_id(); $form->keywords = get_params('keyword',''); $form->status = 1; return $this->asJson($form->getList()); } /** * 配送单分配司机 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/28 15:12 */ public function actionSetDriver() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->driver_id = post_params('driver_id',0); $form->sorting_id = post_params('sorting_id',[]); return $this->asJson($form->setDriver()); } /** * 打印提货单信息 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/28 15:54 */ public function actionPrintTicket() { $form = new InventoryForm(); $form->store_id = get_store_id(); $form->inventory_id = get_params('id',0); return $this->asJson($form->printTicket()); } /** * 获取自提门店选择列表 * @return \yii\web\Response * @author: hankaige * @Time: 2024/4/26 15:19 */ public function actionGetSelectShopList() { $query = Md::find()->where(['store_id'=>get_store_id(),'is_single'=>0,'is_delete' => 0])->select('id,name,cover_url'); $keyword = get_params('keyword',''); if(!empty($keyword)){ $query->andWhere(['like','name',$keyword]); } $result = pagination_make($query); $result['data'] = $result['list']; unset($result['list']); return $this->asJson(['code'=>0,'data'=>$result,'msg'=>'数据获取成功']); } public function actionSetShopSingle() { $mdId = get_params('id'); $md = Md::findOne($mdId); if(empty($md)){ return $this->asJson(['code'=>1,'data'=>[],'msg'=>'门店不存在']); } $md->is_single = 1; if($md->save()){ return $this->asJson(['code'=>0,'data'=>[],'msg'=>'设置成功']); }else{ return $this->asJson(['code'=>1,'data'=>[],'msg'=>'设置失败']); } } //通过店铺获取门店列表 public function actionGetStoreMdList() { $store_id = get_store_id(); $type = get_params('type', 0);//0获取所有门店 1排除绑定过仓库的门店 $field = "id, name"; $filter_md_id = []; switch ($type) { case 1: $filter_md_id = AgentFrontBind::find()->where([ 'type' => AgentFrontBind::TYPE_STORE, 'type_id' => $store_id, 'is_delete' => 0, 'status' => 1 ])->andWhere(['>', 'md_id', 0])->select('md_id')->column(); } return $this->asJson([ 'code' => 0, 'data' => MdForm::getMdList($store_id, $field, $filter_md_id), 'msg' => '数据获取成功' ]); } }