asJson([ 'code' => 0, 'msg' => 'success', 'data' => $mdCategory ]); } public function actionList() { $form = new MdListForm(); $form->page = get_params('page', 1); $form->longitude = get_params('longitude', 1); $form->latitude = get_params('latitude', 1); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * @return \yii\web\Response */ public function actionSubmit() { $saas_user_id = get_saas_user_id(); $name = post_params('name'); $mobile = post_params('mobile'); $province = post_params('province'); $city = post_params('city'); $district = post_params('district'); $logo = post_params('logo'); $contact = post_params('contact'); $address = post_params('address'); $user_name = post_params('user_name') ?: $mobile; $longitude = post_params('longitude'); $latitude = post_params('latitude'); $password = post_params('password') ?: $mobile; $cat_id = post_params('cat_id'); if (empty($contact) || empty($name) || empty($mobile) || empty($logo) || empty($province) || empty($city) || empty($district) || empty($address) || empty($user_name) || empty($password)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } $admin = Admin::find()->where(['username' => $user_name, 'is_delete' => 0])->one(); $md = Md::find()->where(['store_id' => get_store_id(), 'user_name' => $user_name, 'is_delete' => 0])->one(); if (!empty($admin) || !empty($md)) { return $this->asJson([ 'code' => 1, 'msg' => '用户名已经存在,请更换' ]); } $md_staff = MdStaff::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'store_id' => get_store_id()]); if ($md_staff) { return $this->asJson([ 'code' => 1, 'msg' => '由于您属于其他门店员工,暂时无法创建门店' ]); } $admin = Md::find()->where(['store_id' => get_store_id(), 'mobile' => $mobile, 'is_delete' => 0])->andWhere(['in', 'shop_audit', [0, 1]])->one(); if ($admin) { return $this->asJson([ 'code' => 1, 'msg' => '当前注册手机号店铺已存在或存在待审核记录' ]); } if ($cat_id > 0) { $mdCategory = MdCategory::getList(get_store_id(), $cat_id); if (!$mdCategory) { return $this->asJson([ 'code' => 1, 'msg' => '门店分类不存在' ]); } } $md = new Md(); $md->store_id = get_store_id(); $md->user_id = $saas_user_id; $md->name = $name; $md->address = $address; $md->mobile = $mobile; $md->contact = $contact; $md->cover_url = $logo; $md->province = $province; $md->city = $city; $md->district = $district; $md->user_name = $user_name; $md->longitude = $longitude; $md->latitude = $latitude; $md->password = \Yii::$app->security->generatePasswordHash($password); $md->cat_id = $cat_id ?: 0; if ($md->save()) { return $this->asJson([ 'code' => 0, 'msg' => '提交成功' ]); } return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } public function actionMdCenter() { $saas_user_id = get_saas_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id'=> $store_id, 'is_delete' => 0, 'shop_audit' => 1, 'manager' => $saas_user_id])->asArray()->one(); if (empty($md)) { return $this->asJson([ 'code' => 1, 'msg' => '门店信息不存在或未拥有该门店的权限' ]); } // 利润佣金 $md['sale_profit'] = MdProfit::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_send' => 1, 'is_clerk' => 0])->sum('sale_profit'); // 销售佣金 $md['pay_profit'] = MdProfit::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_send' => 1, 'is_clerk' => 0])->sum('pay_profit'); // 统计自提订单信息 $md['offline_order'] = [ 'not_send' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>0, 'is_offline' => 1])->count(), 'send' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>2, 'is_offline' => 1])->count(), 'confirm' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>3, 'is_offline' => 1, 'is_recycle'=>0])->count(), 'wait_sale' => OrderRefund::find()->alias('or')->leftJoin(['o' => Order::tableName()],'or.order_id = o.id')->where(['or.store_id' => $store_id, 'or.md_id' => $md['id'], 'o.is_delete' => 0, 'or.is_delete' => 0, 'or.status' => 0])->andWhere(['o.is_offline' => 1])->count(),// 待售后 ]; // 统计门店订单信息 $md['all_order'] = [ 'not_send' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>0,])->count(), 'send' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>2])->count(), 'confirm' => Order::find()->where(['store_id' => $store_id, 'md_id' => $md['id'], 'is_delete' => 0])->andWhere(['trade_status'=>3, 'is_recycle'=>0])->count(), 'wait_sale' => OrderRefund::find()->alias('or')->leftJoin(['o' => Order::tableName()],'or.order_id = o.id')->where(['or.store_id' => $store_id, 'or.md_id' => $md['id'], 'o.is_delete' => 0, 'or.is_delete' => 0, 'or.status' => 0])->count(),// 待售后 ]; // 未结算收益 $md['not_send_profit'] = MdProfit::find()->alias('mp')->leftJoin(['o' => Order::tableName()], 'mp.order_id = o.id') ->where(['mp.store_id' => $store_id, 'mp.md_id' => $md['id'], 'mp.is_send' => 0])->andWhere(['NOT IN', 'o.trade_status', [-1, 1]]) ->sum('mp.total_profit') ?? 0; // 已提现佣金 $md['cash'] = bcsub($md['total_profit'] , $md['cash_profit'],2); return $this->asJson([ 'code' => 0, 'data' => $md ]); } public function actionStaffCenter() { $saas_user = get_saas_user(); $saas_user_id = $saas_user->id; $store_id = get_store_id(); $md_staff = MdStaff::find()->where(['store_id' => $store_id, 'saas_user_id' => $saas_user_id, 'is_disable' => 0, 'is_delete' => 0])->asArray()->one(); if (empty($md_staff)) { return $this->asJson([ 'code' => 1, 'msg' => '您未有所属门店或权限被限制' ]); } $md = Md::findOne($md_staff['md_id']); // 已核销订单数量 $md_staff['clerk_count'] = MdProfit::find()->where(['store_id' => $store_id, 'md_id' => $md_staff['md_id'], 'is_clerk' => 1, 'clerk_id' => $md_staff['id'], 'is_send' => 1])->count(); // 待核销订单数量 $md_staff['no_clerk_count'] = MdProfit::find()->where(['store_id' => $store_id, 'md_id' => $md_staff['md_id'], 'is_clerk' => 1, 'is_send' => 0]) ->andWhere(['order_id' => Order::find()->select('id')->where(['trade_status' => [Order::ORDER_FLOW_NO_SEND, Order::ORDER_FLOW_NO_SEND], 'is_pay' => 1, 'is_recycle' => 0])]) ->count(); $md_staff['avatar'] = $saas_user->avatar; $md_staff['name'] = $saas_user->name; $md_staff['md_name'] = $md->name; $md_staff['md_logo'] = $md->cover_url; $md_staff['md_shop_time_type'] = $md->shop_time_type; $md_staff['md_start_time'] = $md->start_time; $md_staff['md_end_time'] = $md->end_time; return $this->asJson([ 'code' => 0, 'data' => $md_staff ]); } public function actionAuditStatus() { $saas_user_id = get_saas_user_id(); $md = Md::find()->where(['user_id' => $saas_user_id, 'store_id' => get_store_id(), 'is_delete' => 0])->orderBy('id desc')->limit(1)->one(); if (!$md) { return $this->asJson([ 'code' => 0, 'msg' => '没有审核记录', 'data' => ['status' => -1] ]); } return $this->asJson([ 'code' => 0, 'data' => ['status' => $md->shop_audit] ]); } public function actionSetting() { $open_status = post_params('open_status'); $saas_user_id = get_saas_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的权限' ]); } $md->open_status = intval($open_status); if (!$md->save()) { return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } return $this->asJson([ 'code' => 0, 'data' => '保存成功' ]); } /** * 保存门店设置 * @return \yii\web\Response * @author: hankaige * @Time: 2024/4/8 09:37 */ public function actionHandleSetting() { $saas_user_id = get_saas_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的权限' ]); } $md->cover_url = post_params('cover_url'); $md->name = post_params('name'); $md->mobile = post_params('mobile'); $md->address = post_params('address'); if(post_params('start_time') == '00:00' && post_params('end_time') == '23:59'){ $md->shop_time_type = 1; } $md->start_time = post_params('start_time'); $md->end_time = post_params('end_time'); $md->open_status = post_params('open_status'); if(!$md->save()){ return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } return $this->asJson([ 'code' => 0, 'data' => '保存成功' ]); } public function actionOtherInfo() { $store = Store::findOne(get_store_id()); $pics = $store->md_banner ? Json::decode($store->md_banner) : []; return $this->asJson([ 'code' => 0, 'data' => [ 'md_agreement' => $store->md_agreement, 'md_banner' => $pics, 'md_category' => MdCategory::getList(get_store_id()) ] ]); } public function actionSelectList() { $page = get_params('page', 1); $limit = get_params('limit', 20); $query = SaasUser::find() ->where(['is_delete' => SaasUser::DELETE_STATUS_FALSE]) ->andWhere(['not', ['name' => '']]); if (!empty(get_params('keyword'))) { $query->andWhere(['like', 'name', get_params('keyword')]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('id, name, avatar')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('created_at desc')->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count ] ]); } public function actionStaffAdd() { $store_id = get_store_id(); $manager_user_id = get_saas_user_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $manager_user_id], ['manager' => $manager_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的权限' ]); } $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' => '参数有误' ]); } $staff = MdStaff::findOne(['store_id' => $store_id, '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' => '保存成功' ]); } public function actionStaffList() { $keyword = get_params('keyword', ''); $page = get_params('page', 1); $limit = get_params('limit', 20); $store_id = get_store_id(); $saas_user_id = get_saas_user_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的查看员工权限' ]); } $query = MdStaff::find()->where(['is_delete' => 0, 'store_id' => $store_id, 'md_id' => $md->id]); if (!empty($keyword)) { $query->andWhere([ 'or', ['like', 'name', $keyword], ['like', 'mobile', $keyword] ]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('id, name, mobile, md_id')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('created_at desc')->asArray()->all(); foreach ($list as &$value) { $value['avatar'] = SaasUser::findOne($value['saas_user_id'])->avatar; $value['clerk_count'] = MdProfit::find()->where(['store_id' => $store_id, 'clerk_id' => $value['id'], 'md_id' => $value['md_id'], 'is_clerk' => 1, 'is_send' => 1])->count(); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count ] ]); } public function actionUserList() { $store_id = get_store_id(); $saas_user_id = get_saas_user_id(); $page = get_params('page', 1); $limit = get_params('limit', 20); $keyword = get_params('keyword', ''); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的查看用户权限' ]); } $user_id_arr = Order::find()->where(['md_id' => $md->id, 'is_pay' => 1])->select('user_id')->distinct()->asArray()->all(); $arr = []; foreach ($user_id_arr as $value) { $query = SaasUser::find()->where(['mobile' => User::findOne($value['user_id'])->binding]); if ($keyword) { $query->andWhere(['like', 'name', $keyword]); $saas_user = $query->one(); } else { $saas_user = $query->one(); } if ($saas_user) { $tmp = [ 'create_time' => date('Y-m-d', $saas_user->created_at), 'name' => $saas_user->name, 'avatar' => $saas_user->avatar, 'order_count' => Order::find()->where(['md_id' => $md->id, 'is_pay' => 1, 'user_id' => $value['user_id']])->count(), 'order_price' => Order::find()->where(['md_id' => $md->id, 'is_pay' => 1, 'user_id' => $value['user_id']])->sum('pay_price') ]; $arr[] = $tmp; } } if (empty($arr)) { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => 0, 'page_count' => 0, 'list' => $arr, ], ]); } $data = array_slice($arr, ($page - 1) * $limit, $limit); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => count($arr), 'page_count' => ceil(count($arr) / $limit), 'list' => $data, ] ]); } public function actionStaffClerkDetail() { $id = get_params('id', 0); $page = get_params('page', 1); $limit = get_params('limit', 20); $store_id = get_store_id(); $saas_user_id = get_saas_user_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的查看员工核销详情权限' ]); } $md_staff = MdStaff::findOne($id); if (!$md_staff) { return $this->asJson([ 'code' => 1, 'msg' => '未找到该员工相关信息' ]); } $query = MdProfit::find()->where(['store_id' => $store_id, 'clerk_id' => $md_staff->id, 'md_id' => $md->id, 'is_send' => 1]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('updated_at as clerk_time, order_id')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('created_at desc')->asArray()->all(); foreach ($list as &$value) { $value['clerk_time'] = date('Y-m-d H:i:s', $value['clerk_time']); $order = Order::findOne($value['order_id']); $value['order_no'] = $order->order_no; $value['pay_price'] = $order->pay_price; $value['goods_list'] = OrderDetail::find()->where(['order_id' => $value['order_id']])->select('goods_name, num, attr, pic, total_price')->asArray()->all(); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count ] ]); } public function actionOfflineOrder() { $page = get_params('page', 1); $keyword = get_params('keyword', ''); $limit = get_params('limit', 20); // status -1 全部 0待发货 2待自提 3已完成 4待售后 $status = get_params('status', -1); $order_user_id = get_params('saas_user_id'); $orderSaasUser = SaasUser::findOne($order_user_id); $store_id = get_store_id(); $mdStaff = MdStaff::findOne([ 'saas_user_id'=> get_saas_user_id(), 'store_id' => $store_id, 'is_delete' => 0, 'is_disable' => 0 ]); $md_id = $mdStaff ? $mdStaff->md_id : 0; $user_id = User::findOne(['store_id' => $store_id,'binding' => $orderSaasUser->mobile])->id; $query = Order::find()->alias('o')->where([ 'o.store_id' => $store_id, 'o.is_pay' => 1, 'o.is_recycle' => 0, 'o.is_offline' => 1 ])->andWhere(['!=', 'o.pay_type', 2]); if ($user_id) { $query->andWhere(['o.user_id' => $user_id]); } if ($md_id > 0) { $query->andWhere(['o.md_id' => $md_id]); } // 之前判断是佣金是否发放 if ($status > -1) { if (intval($status) === 4) { $query->leftJoin(['or' => OrderRefund::tableName()], 'or.order_id = o.id') ->andWhere(['OR', ['or.status' => 0], ['or.is_agree' => 0]]); } else { // $query->andWhere(['mp.is_send' => $status]); $query->andWhere(['o.trade_status' => $status]); } } if (!empty($keyword)) { $query->andWhere([ 'or', ['like', 'o.order_no', $keyword], ['like', 'o.name', $keyword], ]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('o.order_no, o.id, o.name, o.mobile, o.pay_price, o.order_type, o.created_at,o.remark,o.words,o.trade_status,o.md_id,o.mch_id')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('o.created_at desc')->asArray()->all(); foreach ($list as &$value) { $value['goods_list'] = OrderDetail::find()->where(['order_id' => $value['id']])->select('goods_name, num, attr, pic, total_price')->asArray()->all(); $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $value['trade_status_text'] = Order::getStatusText($value['trade_status']); $value['checked'] = 0; $value['disabled'] = $value['trade_status'] == 2 || $value['trade_status'] == 0 ? 0 : 1; $orderRefund = OrderRefund::findOne(['order_id' => $value['id'], 'user_delete' => 0, 'is_delete' => 0]); $value['refund'] = null; if ($orderRefund) { $value['refund'] = [ 'is_agree' => intval($orderRefund->is_agree),//0=待处理,1=已同意,2=已拒绝 'status' => intval($orderRefund->status),//0=待商家处理,1=同意并已退款,2=已同意换货,3=已拒绝退换货 'is_user_send' => intval($orderRefund->is_user_send),//用户是否发货 'refund_type' => intval($orderRefund->type),//1退款退货 2换货 'is_user_cancel' => intval($orderRefund->is_user_cancel), //用户是否取消售后申请 0/1 'id' => $orderRefund->id ]; } // 显示门店名称 或者 入住商名称 if($value['md_id'] > 0){ $value['shop_name'] = Md::findOne(['id' => $value['md_id']])->name; }elseif($value['mch_id']){ $value['shop_name'] = Mch::findOne(['id' => $value['mch_id']])->name; } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'no_clerk_count' => 0,// 前端已经没有用到这个值了 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count ] ]); } public function actionOrderDetail() { $order = Order::findOne([ 'id' => get_params('order_id'), 'is_delete' => 0, ]); if (!$order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在', ]); } $goods_list = OrderDetail::find()->alias('od') ->where(['od.order_id' => $order->id, 'od.is_delete' => 0])->asArray()->all(); $num = 0; foreach ($goods_list as $i => $item) { $goods = Json::decode($item['goods_info']); $newItem = []; $newItem['goods_id'] = $item['goods_id']; $newItem['order_detail_id'] = $item['id']; $newItem['name'] = $item['goods_name'] ?: $goods['name']; $newItem['total_price'] = $item['total_price']; $newItem['num'] = $item['num']; $newItem['attr'] = json_decode($item['attr']); $num += intval($item['num']); $newItem['goods_pic'] = $item['pic'] ?: $goods['cover_pic']; //取消信息 $cancel_info = []; $cancel_info['num'] = OrderGoodsCancel::find()->where([ 'order_id' => $order->id, 'order_detail_id' => $item['id'], 'status' => [ OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY, OrderGoodsCancel::STATUS_PAY_FAIL, ] ])->sum('num') ?: 0; $cancel_info['cancel_list'] = OrderGoodsCancel::find()->where([ 'order_id' => $order->id, 'order_detail_id' => $item['id'], 'status' => [ OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY, OrderGoodsCancel::STATUS_PAY_FAIL, ] ])->orderBy('id desc') ->select('status, num, refund_price, created_at, updated_at') ->asArray() ->all(); foreach ($cancel_info['cancel_list'] as &$cancel_item) { $cancel_item['status_text'] = OrderGoodsCancel::$status_text[$cancel_item['status']]; $cancel_item['status'] = intval($cancel_item['status']); if ($cancel_item['status'] === OrderGoodsCancel::STATUS_PAY) { $cancel_item['status'] = 1; } if ($cancel_item['status'] === OrderGoodsCancel::STATUS_PAY_FAIL) { $cancel_item['status'] = 0; } if ($cancel_item['status'] === OrderGoodsCancel::STATUS_CANCEL) { $cancel_item['status'] = 2; } $cancel_item['created_at'] = date('Y-m-d H:i:s', $cancel_item['created_at']); if (in_array($cancel_item['status'], [OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_REFUSE])) { $cancel_item['created_at'] = date('Y-m-d H:i:s', $cancel_item['updated_at']); } } $newItem['cancel_info'] = $cancel_info; $newItem['cancel_num'] = OrderGoodsCancel::find()->where([ 'order_detail_id' => $item['id'], 'status' => [ OrderGoodsCancel::STATUS_PAY, OrderGoodsCancel::STATUS_PASS, OrderGoodsCancel::STATUS_PAY_FAIL ] ])->sum('num') ?: 0; $newItem['cancel_text'] = ''; if ($newItem['cancel_num'] > 0) { $newItem['cancel_text'] = '已退款' .$newItem['cancel_num'] .'件'; if ($newItem['cancel_num'] >= $item['num']) { $newItem['cancel_text'] = '已退款'; } } $newList[] = $newItem; } $md_id = $order->md_id; $order_type = (int)$order->order_type; if ($md_id > 0) { $md = Md::findOne($md_id); } $diy_shop_name = Option::get(OptionSetting::DIY_SHOP_NAME, $order->store_id, 'pay', Option::get(OptionSetting::DIY_SHOP_NAME, $order->store_id, 'store', '自提配送')['value'] ?: '自提配送')['value']; $diy_express_name = Option::get(OptionSetting::DIY_EXPRESS_NAME, $order->store_id, 'pay', Option::get(OptionSetting::DIY_EXPRESS_NAME, $order->store_id, 'store', '快递配送')['value'] ?: '快递配送')['value']; $store = Store::findOne($order->store_id); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'order_id' => $order->id, 'is_pay' => $order->is_pay, 'name' => $order->name, 'mobile' => $order->mobile, 'address' => $order->address, 'order_no' => $order->order_no, 'addtime' => date('Y-m-d H:i', $order->created_at), 'total_price' => doubleval(sprintf('%.2f', $order->total_price)), 'goods_total_price' => doubleval(sprintf('%.2f', doubleval($order->total_price) - doubleval($order->express_price))), 'pay_price' => $order->pay_price, 'num' => $num, 'goods_list' => $newList, 'is_offline' => $order->is_offline, 'diy_express_name' => intval($order->is_offline) === 1 ? $diy_shop_name : $diy_express_name, 'pay_type' => $order->pay_type, 'apply_delete' => $order->apply_delete, 'trade_status' => $order->trade_status, 'is_send' => MdProfit::findOne(['order_id' => $order->id])->is_send, 'order_type' => (int)$order->order_type, 'mch_name' => $store->name ?: '平台自营', 'md_name' => !empty($md) ? $md->name : '', 'md_mobile' => !empty($md) ? $md->mobile : '', 'md_address' => !empty($md) ? $md->address : '', ], ]); } public function actionSendOrder() { $order_id = post_params('order_id', []); $order_id = Json::decode($order_id); $express = post_params('express', ''); $expressNo = post_params('express_no', ''); if (empty($order_id) || !is_array($order_id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } $t = \Yii::$app->db->beginTransaction(); foreach ($order_id as $value) { $order = Order::findOne($value); if ($order->is_pay == 0) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '存在异常订单' ]); } if ((int)$order->trade_status !== 0) { return $this->asJson([ 'code' => 1, 'msg' => '订单状态异常' ]); } $order->send_time = time(); $order->trade_status = 2; $order->express = $express; $order->express_no = $expressNo; if (!$order->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => implode(';', array_values($order->firstErrors)) ]); } } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '处理完成' ]); } public function actionClerkOrder() { $order_id = post_params('order_id', []); $order_id = Json::decode($order_id); if (empty($order_id) || !is_array($order_id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } $saas_user_id = get_saas_user_id(); $md_staff = MdStaff::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'store_id' => get_store_id()]); $user = get_user_id(); $mch_staff = MchStaff::findOne(['user_id' => $user, 'is_delete' => 0, 'store_id' => get_store_id()]); // if (!$md_staff) { // return $this->asJson([ // 'code' => 1, // 'msg' => '当前无可操作权限' // ]); // } // if ($md_staff->is_disable) { // return $this->asJson([ // 'code' => 1, // 'msg' => '核销权限已被禁用' // ]); // } foreach ($order_id as $value) { $t = \Yii::$app->db->beginTransaction(); $order = Order::findOne($value); //如果订单已经取消 if ($order->apply_delete == Order::ORDER_APPLY_DELETE || $order->trade_status == Order::ORDER_FLOW_CANCEL) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '订单已取消或申请取消中,不可核销' ]); } if ($order->is_pay == 0) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '存在异常订单' ]); } if($order->md_id > 0 && $md_staff->md_id != $order->md_id){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '暂无核销权限' ]); } if($order->mch_id > 0 && $mch_staff->mch_id != $order->mch_id){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '暂无核销权限' ]); } if($order->md_id > 0){ $mp_profit = MdProfit::findOne(['order_id' => $value]); if ($md_staff->md_id != $mp_profit->md_id) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作异常' ]); } if ($mp_profit->is_clerk == 1 && $mp_profit->is_send == 0) { $mp_profit->is_send = 1; $mp_profit->clerk_id = $md_staff->id; $mp_profit->updated_at = time(); if (!$mp_profit->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $mp_profit->errors[0] ]); } $md = Md::findOne($mp_profit->md_id); $md->total_profit += $mp_profit->total_profit; $md->cash_profit += $mp_profit->total_profit; $md->clerk_profit += $mp_profit->clerk_profit; if (!$md->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } $order->clerk_id = get_user_id(); $order->trade_status = 3; $order->confirm_time = time(); if (!$order->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $order->errors ]); } } } if($order->mch_id > 0){ $order->clerk_id = get_user_id(); $order->trade_status = Order::ORDER_FLOW_CONFIRM; $order->confirm_time = time(); if ($order->pay_type == 2) { $order->is_pay = 1; $order->pay_time = time(); } $order->save(); } $t->commit(); } return $this->asJson([ 'code' => 0, 'msg' => '处理成功' ]); } /** * 获取佣金相关 */ public function actionGetPrice() { $saas_user_id = get_saas_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的权限' ]); } $res = [ 'cash_profit' => $md->cash_profit ]; // 新提现方式 $model = MdSetting::find()->where(['store_id' => $this->store_id])->one(); $wxappUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/wxapp/images'; $payTypeList = [ [ 'icon' => $wxappUrl . '/icon-share-wechat.png', 'name' => '微信', 'is_show' => $model['pay_wechat'] ? true : false, 'type' => 'wechat' ], [ 'icon' => $wxappUrl . '/icon-share-ant.png', 'name' => '支付宝', 'is_show' => $model['pay_alipay'] ? true : false, 'type' => 'alipay' ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '银行卡', 'is_show' => $model['pay_bank'] ? true : false, 'type' => 'bank_card' ], [ 'icon' => $wxappUrl . '/gold.png', 'name' => '余额', 'is_show' => $model['pay_remaining'] ? true : false, 'type' => 'money' ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '灵工', 'is_show' => $model['pay_lg'] ? true : false, 'type' => 'lg' ], ]; $res['pay_type_list'] = $payTypeList; $res['cash_method_list'] = []; $saas_user = get_saas_user(); $cash_method = []; $lg = Lg::find()->where(['store_id' => $this->store_id,'user_id'=>$saas_user->id,'status'=>1,'is_delete'=>0])->one(); if (!empty($saas_user->withdraw_method)) { $cash_method = json_decode($saas_user->withdraw_method, true); if ($lg){ //灵工 $cash_method = array_merge($cash_method, [[ 'type' => 'lg' ]]); } if (is_array($cash_method)) { $res['cash_method_list'] = $cash_method; } }else{ if($lg){ //灵工 $cash_method[]['type'] = 'lg'; $res['cash_method_list'] = array_values($cash_method); } } $money = [ [ 'type' => 'money' ] ]; $cash_method = array_merge($cash_method, $money); if (is_array($cash_method)) { foreach ($cash_method as $index => &$item) { if ($item['type'] === 'wechat' && $payTypeList[0]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'alipay' && $payTypeList[1]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'bank_card' && $payTypeList[2]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'money' && $payTypeList[3]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'lg' && $payTypeList[4]['is_show'] === false) { unset($cash_method[$index]); } } $res['cash_method_list'] = array_values($cash_method);; } $res['cash_service_charge'] = $model['cash_service_charge'] ?? 0; $res['min_money'] = $model['min_money'] ?? 0; return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]); } /** * 获取提现方式 */ public function actionGetCashMethod() { $mdSetting = MdSetting::findOne(['store_id' => $this->store_id]); $saas_user = get_saas_user(); $cash_method = []; $payTypeList = [ [ 'name' => '微信', 'is_show' => (bool)$mdSetting['pay_wechat'], 'type' => 'wechat', 'is_bind' => false ], [ 'name' => '支付宝', 'is_show' => (bool)$mdSetting['pay_alipay'], 'type' => 'alipay', 'is_bind' => false ], [ 'name' => '银行卡', 'is_show' => (bool)$mdSetting['pay_bank'], 'type' => 'bank_card', 'is_bind' => false ], [ 'name' => '灵工', 'is_show' => (bool)$mdSetting['pay_lg'], 'type' => 'lg', 'is_bind' => false ], ]; $lg = Lg::find()->where(['store_id' => $this->store_id,'user_id'=>$saas_user->id,'status'=>1,'is_delete'=>0])->one(); if (!empty($saas_user->withdraw_method)) { $decode = json_decode($saas_user->withdraw_method, true); if ($lg){ //灵工 $decode = array_merge($decode, [[ 'type' => 'lg' ]]); } if (is_array($decode)) { $cash_method = $decode; foreach ($payTypeList as &$pay_item) { foreach ($cash_method as $item) { if ($item['type'] === $pay_item['type']) { $pay_item['is_bind'] = true; $pay_item = array_merge($pay_item, $item); } } } } }else{ if($lg){ //灵工 $cash_method[]['type'] = 'lg'; $res['cash_method_list'] = array_values($cash_method); } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $payTypeList, ], ]); } /** * 获取提现方式 */ public function actionDelCashMethod() { $saas_user = get_saas_user(); $type = post_params('type'); if (empty($type)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } if ($type == 'lg'){ $lg = Lg::find()->where(['user_id'=>$saas_user->id,'is_delete'=>0])->one(); if ($lg){ $lg->is_delete = 1; $lg->save(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } } if (empty($saas_user->withdraw_method)) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } $cash_method = json_decode($saas_user->withdraw_method, true); if (is_array($cash_method)) { foreach ($cash_method as $key => $value) { if ($value['type'] == $type) { unset($cash_method[$key]); } } $saas_user->withdraw_method = json_encode(array_values($cash_method)); } else { $saas_user->withdraw_method = ''; } if ($saas_user->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } return $this->asJson([ 'code' => 0, 'msg' => '操作失败', ]); } /** * 添加提现方式 */ public function actionAddCashMethod() { $type = post_params('type'); if (empty($type)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $name = post_params('name'); $account = post_params('account'); $bank = post_params('bank'); if (empty($name) || empty($account)) { return $this->asJson([ 'code' => 1, 'msg' => '账号和姓名不能为空', ]); } if ($type == 'bank_card' && empty($bank)) { return $this->asJson([ 'code' => 1, 'msg' => '银行不能为空', ]); } $data = [ 'type' => $type, 'name' => $name, 'account' => $account, ]; if ($type == 'bank_card') { $data['bank'] = $bank; } $saas_user = get_saas_user(); if (empty($saas_user->withdraw_method)) { $saas_user->withdraw_method = json_encode(array_values([$data])); } else { $decode = json_decode($saas_user->withdraw_method, true); if (!$decode) { $saas_user->withdraw_method = json_encode(array_values([$data])); } else { foreach ($decode as $key => $value) { if ($value['type'] == $type) { unset($decode[$key]); break; } } $decode[] = $data; $saas_user->withdraw_method = json_encode(array_values($decode)); } } if ($saas_user->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } public function actionCashApply() { $price = post_params('cash'); $type = post_params('type'); if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat','money','lg'])) { return $this->asJson([ 'code' => 1, 'msg' => '参数非法', ]); } $saas_user_id = get_saas_user_id(); $user_id = get_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的权限' ]); } if ($price > $md->cash_profit) { return $this->asJson([ 'code' => 1, 'msg' => '当前大于可提现金额' ]); } $exit = Cash::find()->andWhere(['=', 'status', 0])->andWhere(['user_id' => $user_id, 'store_id' => $store_id, 'cash_type' => 2])->exists(); if ($exit) { // return $this->asJson([ // 'code' => 1, // 'msg' => '尚有未完成的提现申请' // ]); } $setting = MdSetting::findOne(['store_id'=>get_store_id()]); // 每日提现金额限制 if ($setting['cash_max_day']) { $cash_sum = Cash::find()->where([ 'store_id' => $this->store_id, 'is_delete' => 0, 'status' => [0, 1, 2, 5], ])->andWhere([ 'AND', ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))], ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))], ])->sum('price'); $cash_max_day = $setting['cash_max_day'] - ($cash_sum ? $cash_sum : 0); if ($setting['cash_max_day'] > 0 && $price > $cash_max_day) { return $this->asJson([ 'code' => 1, 'msg' => '提现金额不能超过' . $cash_max_day . '元' ]); } } // 单人每日提现 if ($setting['cash_max_single_day']) { $cash_sum = Cash::find()->where([ 'store_id' => get_store_id(), 'is_delete' => 0, 'status' => [0, 1, 2, 5], 'user_id' => $user_id ])->andWhere([ 'AND', ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))], ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))], ])->sum('price'); $cash_max_single_day_ = $setting['cash_max_single_day'] - ($cash_sum ?: 0); if ($setting['cash_max_single_day'] > 0 && $price > $cash_max_single_day_) { return $this->asJson([ 'code' => 1, 'msg' => '每人每天提现金额不能超过'. $cash_max_single_day_ .'元' ]); } } $user = User::findOne(['id' => $user_id, 'store_id' => get_store_id()]); if (!$user) { return $this->asJson([ 'code' => 1, 'msg' => '网络异常' ]); } if ($price < $setting['min_money']) { return $this->asJson([ 'code' => 1, 'msg' => '提现金额不能小于' . $setting['min_money'] . '元' ]); } $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; if ($type == 'money') { $cash->type = 3; // 2024-12-17 直接完成打款 // $cash->status = Cash::STATUS_RECHARGE;// 余额通过 } else { $saas_user = get_saas_user(); $withdraw_method = Json::decode($saas_user->withdraw_method); $withdraw_method = array_column($withdraw_method, null, 'type'); if ($type == 'wechat') { $cash->type = 0; $cash->name = $withdraw_method['wechat']['name']; $cash->mobile = $withdraw_method['wechat']['account']; } if ($type == 'alipay') { $cash->type = 1; $cash->name = $withdraw_method['alipay']['name']; $cash->mobile = $withdraw_method['alipay']['account']; } if ($type == 'bank_card') { $cash->type = 2; $cash->name = $withdraw_method['bank_card']['name']; $cash->mobile = $withdraw_method['bank_card']['account']; $cash->bank_name = $withdraw_method['bank_card']['bank']; } if ($type == 'lg') { //灵工提现 $lg_info = Lg::find()->where(['user_id'=>$saas_user->id,'is_delete'=>0])->one(); $cash->type = 4; $cash->name = $lg_info->name; $cash->mobile = $lg_info->mobile; } } $cash->pay_time = 0; $cash->service_charge = $setting['cash_service_charge']; $cash->cash_type = 2; if ($cash->save()) { $md->cash_profit -= $cash->price; if (!$md->save()) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $md->errors[0] ]); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '申请成功' ]); } else { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $cash->errors ]); } } public function actionOrderList() { $page = get_params('page', 1); $keyword = get_params('keyword', ''); $limit = get_params('limit', 20); $time = get_params('time', ''); // 前端在写的时候 把-1当作了全部 所以整个status的值-1 $status = (int)get_params('status', -1) - 1; $saas_user_id = get_saas_user_id(); $store_id = get_store_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店查看订单权限' ]); } $query = Order::find()->alias('o')->where([ 'o.is_delete' => 0, 'o.store_id' => $store_id, 'o.user_delete' => 0, 'o.md_id' => $md->id, 'o.is_recycle' => 0 ]); if ($time) { $timestamp = strtotime($time); $start_time = strtotime(date('Y-m-01 00:00:00', $timestamp)); $end_time = $start_time + 30 * 24 * 3600; $query->andWhere(['and', ['>=', 'o.created_at', $start_time], ['<=', 'o.created_at', $end_time]]); } if ($keyword) { $query->andWhere(['like', 'o.order_no', $keyword]); } if(intval($status) == 4){ //待售后 $query->leftJoin(['or' => OrderRefund::tableName()], 'o.id = or.order_id') ->andWhere(['AND', ['IS NOT', 'or.id', NULL], ['or.is_user_cancel' => 0]]); } else { if ($status != -2) { $query->andWhere(['o.trade_status'=>$status]); } } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => $limit]); /* @var Order[] $list */ $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->all(); $new_list = []; foreach ($list as $order) { $order_detail_list = OrderDetail::findAll(['order_id' => $order->id, 'is_delete' => 0]); $goods_list = []; foreach ($order_detail_list as $order_detail) { $goods = json_decode($order_detail->goods_info, true); if (!$goods) { continue; } $goods_pic = $order_detail->pic ?? $goods['cover_pic']; $goods_list[] = (object)[ 'goods_id' => $goods['id'] ?? $order_detail->goods_id, 'goods_pic' => $goods_pic, 'goods_name' => $order_detail->goods_name, 'num' => $order_detail->num, 'price' => $order_detail->total_price, 'attr_list' => json_decode($order_detail->attr), ]; } $orderRefund = OrderRefund::findOne(['order_id' => $order->id, 'user_delete' => 0, 'is_delete' => 0]); $deliveryInfo = null; if ($order->is_delivery == 1) { $deliveryInfo = DeliveryInfo::find()->where(['order_no' => $order->order_no])->one(); } $is_order_refund = $order_refund_enable = 0; if ($orderRefund) { $is_order_refund = 1; } else { $is_order_refund = 0; } if ($order->is_pay == 1 && ($order->trade_status == Order::ORDER_FLOW_SEND || $order->trade_status == Order::ORDER_FLOW_CONFIRM)) { $order_refund_enable = 1; } else { $order_refund_enable = 0; } if ($order->trade_status == Order::ORDER_FLOW_CONFIRM) { $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, $store_id); if ((time() - $order->confirm_time) > $after_sale_time['value'] * 86400) {//超过可售后时间 $order_refund_enable = 0; } } $is_send = 0; $md_profit = MdProfit::findOne(['order_id' => $order->id]); if ($md_profit->is_clerk) { $is_send = $md_profit->is_send; } $trade_status_text = Order::getStatusText($order->trade_status); $refund = null; if ($orderRefund) { $refund = [ 'is_agree' => intval($orderRefund->is_agree),//0=待处理,1=已同意,2=已拒绝 'status' => intval($orderRefund->status),//0=待商家处理,1=同意并已退款,2=已同意换货,3=已拒绝退换货 'is_user_send' => intval($orderRefund->is_user_send),//用户是否发货 'refund_type' => intval($orderRefund->type),//1退款退货 2换货 'is_user_cancel' => intval($orderRefund->is_user_cancel), //用户是否取消售后申请 0/1 'id' => $orderRefund->id ]; if ($order->trade_status === Order::ORDER_FLOW_CONFIRM) { $trade_status_text = "已完成(有售后)"; } } $new_list[] = (object)[ 'is_send' => $is_send, 'is_order_refund' => $is_order_refund, 'order_refund_enable' => $order_refund_enable, 'order_id' => $order->id, 'order_no' => $order->order_no, 'add_time' => $order->created_at, 'created_at' => date('Y-m-d H:i:s',$order->created_at), 'goods_list' => $goods_list, 'total_price' => $order->total_price, 'pay_price' => $deliveryInfo ? sprintf("%1.2f", $order->pay_price + $deliveryInfo->fee) : $order->pay_price, 'is_pay' => $order->is_pay, 'is_comment' => $order->is_comment, 'is_offline' => $order->is_offline, 'offline_qrcode' => $order->offline_qrcode, 'express' => $order->express, 'type' => $order->type, 'pay_type' => $order->pay_type, 'refund' => $refund, 'apply_delete' => $order->apply_delete, 'trade_status' => $order->trade_status, 'delivery_fee' => $deliveryInfo ? $deliveryInfo->fee : 0, 'is_delivery' => $order->is_delivery, 'trade_status_text' => $trade_status_text, 'remark' => $order->remark,// 买家留言 'words' => $order->words,// 商家备注 'address_name' => $order->name,// 自提信息 'address_mobile' => $order->mobile,// 自提手机号 'address' => $order->address,// 收货地址 ]; } $refund_address = RefundAddress::find()->where(['store_id' => $store_id, 'is_delete' => 0]) ->select('id, name, address, mobile')->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $new_list, 'refund_address' => $refund_address ], ]); } public function actionProfitDetail() { $page = get_params('page', 1); $limit = get_params('limit', 20); $status = get_params('status', 0); $date_time = strtotime(get_params('queryDate', 0)); $year = date('Y', $date_time); $mouth = date('m', $date_time); $mouth_end = date('t', $date_time); $start_date = strtotime($year. '-' . $mouth . '-' . '01'); $end_date = strtotime($year. '-' . $mouth . '-' . $mouth_end) + (60 * 60 * 24); $store_id = get_store_id(); $saas_user_id = get_saas_user_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的查看员工核销详情权限' ]); } $query = MdProfit::find()->alias('mp')->leftJoin(['o' => Order::tableName()], 'mp.order_id = o.id') ->where(['mp.store_id' => $store_id, 'mp.md_id' => $md->id])->andWhere(['NOT IN', 'o.trade_status', [-1, 1]]); if (!empty($date_time)) { $query->andWhere(['and', ['>=', 'mp.created_at', $start_date], ['<=', 'mp.created_at', $end_date]]); } if ($status != 0 && in_array($status, [1, 2])) { $query->andWhere(['mp.is_send' => $status == 2 ? 1 : 0]); } $count = $query->count(); $total_price = $query->sum('mp.total_profit'); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('mp.*')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('created_at desc')->asArray()->all(); foreach ($list as &$value) { $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); $value['updated_at'] = date('Y-m-d H:i:s', $value['updated_at']); $order = Order::findOne($value['order_id']); $value['order_no'] = $order->order_no; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count, 'total_price' => $total_price ] ]); } public function actionCashDetail() { $page = get_params('page', 1); $limit = get_params('limit', 20); $status = get_params('status', -1); $store_id = get_store_id(); $saas_user_id = get_saas_user_id(); $md = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店的查看员工核销详情权限' ]); } $query = Cash::find()->where(['store_id' => $store_id, 'md_id' => $md->id]); if ($status != -1) { $query->andWhere(['status' => $status]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]); $list = $query->select('*')->limit($pagination->limit) ->offset($pagination->offset)->orderBy('created_at desc')->asArray()->all(); foreach ($list as &$value) { $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->pageCount, 'row_count' => $count ] ]); } public function actionGetQrcode() { $saas_user_id = get_saas_user_id(); $scene = "{$saas_user_id}"; if (is_wechat_platform()) { $res = ShareQrcode::wxQrcode('md_admin/md-center/self-mention', $scene); if (isset($res['code']) && $res['code'] == 1) { return $this->asJson([ 'code' => 1, 'msg' => $res['response']['errmsg'], ]); } } elseif (is_alipay_platform()) { $res = ShareQrcode::getAlipayQrcode('md_admin/md-center/self-mention', $scene); if (empty($res['code']) || $res['code'] != 10000) { return $this->asJson($res); } $res['url_path'] = $res['qr_code_url_circle_blue']; } else { $file_name = md5('md_admin/md-center/self-mention' . $scene.get_store_id()); // 保存小程序码到文件 $dir = \Yii::$app->runtimePath . '/image/wx_qrcode'; if (! is_dir($dir)) { mkdir($dir, 0777, true); } $url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/wx_qrcode/' . $file_name); QrCode::image(\Yii::$app->request->hostInfo . '/h5/#/md_admin/md-center/self-mention', 600, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $dir. '/' .$file_name . '.jpg'); $res = [ 'code' => 0, 'root_path' => $dir . '/' . $file_name . '.jpg', 'url_path' => $url . '.jpg', ]; } $level = User::findOne(get_user_id())->level; $level_name = Level::findOne(['level' => $level])->name; $id = sprintf("%011d", get_user_id()); $generator = new BarcodeGeneratorJPG(); $barcode = $generator->getBarcode($id, $generator::TYPE_CODE_128, 2, 30); $filename = md5('user_clerk_' . $id); $code_path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); file_put_contents($code_path, $barcode); // $barcode = base64_encode($barcode); return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $res['url_path'], 'name' => get_saas_user()->name, 'avatar' => get_saas_user()->avatar, 'level_name' => $level_name ?: '普通用户', 'code_path' => $pic_url ] ]); } /** * 获取门店推广海报 * @return \yii\web\Response * @author: hankaige * @Time: 2024/3/20 15:02 */ public function actionGetShareQrcode() { $form = new ShareQrcodeForm(); $form->store_id = get_store_id(); $form->type = 11; $form->user = get_user(); $form->user_id = get_user_id(); $form->md_id = get_params('md_id'); return $this->asJson($form->search()); } // 删除已完成订单 也就是加入回收站 public function actionRecycleOrder() { $orderIds = post_params('order_ids',[]); $res = Order::updateAll(['is_recycle' => 1],['id' => $orderIds,'trade_status'=>3,'store_id'=>get_store_id()]); if($res > 0){ return $this->asJson(['code' => 0,'msg'=>'操作成功']); } return $this->asJson(['code' => 1,'msg'=>'订单不存在']); } /** * 到货通知 * @return \yii\web\Response * @author: hankaige * @Time: 2024/4/8 13:49 */ public function actionNotice(){ $orderIds = post_params('order_ids',[]); if(count($orderIds) <= 0){ return $this->asJson(['code'=>1,'msg'=>'请选择要通知订单']); } foreach($orderIds as $orderId){ $order = Order::find()->with(['orderDetail'])->where(['id'=>$orderId])->asArray()->one(); if(empty($order)){ continue; } $goodsName = ''; foreach($order['orderDetail'] as $goods){ $goodsName .= $goods['name'] . ','; } $md = Md::findOne($order['md_id']); NoticeSend::ShopArrive($order['user_id'],$order['mobile'],$order['order_no'],$goodsName,$md->name); } return $this->asJson(['code'=>0,'msg' => '已通知客户']); } // 获取独立店铺的商品列表 public function actionGetGoods(){ $form = new MdGodsForm(); $form->store_id = get_store_id(); $form->md_id = get_params('md_id'); $form->keyword = get_params('keyword',''); $form->status = get_params('status',-1); return $this->asJson($form->getGoodsList()); } public function actionUpdateStatus(){ $form = new MdGodsForm(); $form->store_id = get_store_id(); $form->md_id = get_params('md_id'); $form->status = get_params('status'); $form->ids = get_params('ids'); return $this->asJson($form->batchUpdateStatus()); } public function actionGetGoodsAttr(){ $form = new MdGodsForm(); $form->store_id = get_store_id(); $form->md_id = get_params('md_id'); $form->id = get_params('id'); return $this->asJson($form->getGoodsAttr()); } public function actionSetGoodsInfo(){ $form = new MdGodsForm(); $form->store_id = get_store_id(); $form->md_id = post_params('md_id'); $form->id = post_params('id'); $form->goods_price = post_params('goods_price', 0); $form->goods_num = post_params('goods_num', 0); $form->attr = post_params('attr', 0); $res = $form->setPrice(); return $this->asJson($res); } /** * 设置订单备注 * @return \yii\web\Response * @author: hankaige * @Time: 2024/4/10 16:33 */ public function actionSetOrderWords(){ $orderId = post_params('order_id'); if(empty($orderId)){ return $this->asJson(['code'=>1,'msg'=>'订单ID不能为空']); } $order = Order::findOne($orderId); if(empty($order)){ return $this->asJson(['code'=>1,'msg'=>'订单不存在']); } $words = post_params('words'); if(empty($words)){ return $this->asJson(['code'=>1,'msg'=>'备注不能为空']); } $order->words = $words; $res = $order->save(); if($res){ return $this->asJson(['code'=>0,'msg'=>'保存成功']); } return $this->asJson(['code'=>1,'msg'=>'保存失败']); } public function actionOrderCancel() { $form = new MdOrder(); $form->order_id = get_params('order_id'); $form->store_id = get_store_id(); $form->md_id = get_params('md_id'); return $this->asJson($form->handleCancel()); } /** * 平台商品订单取消 */ public function actionApplyOrderDelete() { $saas_user_id = get_saas_user_id(); $form = new MdOrder(); $form->attributes = post_params(); $form->order_id = post_params('order_id'); $form->store_id = get_store_id(); $md = Md::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'shop_audit' => 1]) ->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店操作订单权限' ]); } $form->md_id = $md->id; return $this->asJson($form->applyOrderDelete()); } /** * 平台商品订单取消 */ public function actionHandleRefund() { $saas_user_id = get_saas_user_id(); $form = new MdOrder(); $form->attributes = post_params(); $form->order_id = post_params('order_id'); $form->store_id = get_store_id(); $md = Md::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'shop_audit' => 1]) ->andWhere(['or', ['user_id' => $saas_user_id], ['manager' => $saas_user_id]])->one(); if (!$md) { return $this->asJson([ 'code' => 1, 'msg' => '未拥有该门店操作订单权限' ]); } $form->md_id = $md->id; return $this->asJson($form->handleRefund()); } }