diff --git a/app/common/dao/marketing/AgentApplyDao.php b/app/common/dao/marketing/AgentApplyDao.php new file mode 100644 index 0000000..e5a2f2d --- /dev/null +++ b/app/common/dao/marketing/AgentApplyDao.php @@ -0,0 +1,90 @@ +when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ + $query->where('id', (int)$params['id']); + }) + ->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){ + $query->where('uid', (int)$params['uid']); + }) + ->when(isset($params['pid']) && $params['pid'] !== '',function($query) use ($params){ + $query->where('pid', (int)$params['pid']); + }) + ->when(isset($params['mer_name']) && $params['mer_name'] !== '',function($query) use ($params){ + $query->where('mer_name', 'like', "%{$params['mer_name']}%"); + }) + ->when(isset($params['contact_name']) && $params['contact_name'] !== '',function($query) use ($params){ + $query->where('contact_name', 'like', "%{$params['contact_name']}%"); + }) + ->when(isset($params['contact_phone']) && $params['contact_phone'] !== '',function($query) use ($params){ + $query->where('contact_phone', $params['contact_phone']); + }) + ->when(isset($params['agent_type']) && $params['agent_type'] !== '',function($query) use ($params){ + $query->where('agent_type', (int)$params['agent_type']); + }) + ->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){ + $query->where('status', (int)$params['status']); + }) + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'province' => function($query){ + $query->field('id,name as province_name,code as province_code')->bind(['province_name', 'province_code']); + }, + 'city' => function($query){ + $query->field('id,name as city_name,code as city_code')->bind(['city_name', 'city_code']); + }, + 'area' => function($query){ + $query->field('id,name as area_name,code as area_code')->bind(['area_name', 'area_code']); + }, + 'street' => function($query){ + $query->field('id,name as street_name,code as street_code')->bind(['street_name', 'street_code']); + }, + 'parent' => function($query){ + $query->field('id,uid,agent_type') + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar')->bind(['nickname','avatar']); + } + ]); + }, + 'merClass' => function($query){ + $query->field('merchant_category_id,category_name as mer_category_name')->bind(['mer_category_name']); + }, + 'merType' => function($query){ + $query->field('mer_type_id,type_name as mer_type_name')->bind(['mer_type_name']); + }, + 'orderInfo' => function($query){ + $query->field('order_id,status,order_sn'); + }, + ]) + ->order('create_time DESC,id DESC'); + } + + + + + + + + +} diff --git a/app/common/dao/store/order/StoreGroupOrderDao.php b/app/common/dao/store/order/StoreGroupOrderDao.php index db115c0..da44a87 100644 --- a/app/common/dao/store/order/StoreGroupOrderDao.php +++ b/app/common/dao/store/order/StoreGroupOrderDao.php @@ -50,7 +50,7 @@ class StoreGroupOrderDao extends BaseDao $query = StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) { $query->where('paid', $where['paid']); }) - ->whereNotIn('activity_type', [30,31]) + ->whereNotIn('activity_type', [30,31,32]) ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) { $query->where('paid', $where['paid']); }) diff --git a/app/common/model/marketing/AgentApply.php b/app/common/model/marketing/AgentApply.php new file mode 100644 index 0000000..2402c86 --- /dev/null +++ b/app/common/model/marketing/AgentApply.php @@ -0,0 +1,69 @@ +hasOne(User::class, 'uid', 'uid'); + } + public function parent(){ + return $this->hasOne(Agent::class, 'id', 'pid'); + } + public function province(){ + return $this->hasOne(CityArea::class, 'id', 'province_id'); + } + public function city(){ + return $this->hasOne(CityArea::class, 'id', 'city_id'); + } + public function area(){ + return $this->hasOne(CityArea::class, 'id', 'area_id'); + } + public function street(){ + return $this->hasOne(CityArea::class, 'id', 'street_id'); + } + + public function merClass(){ + return $this->hasOne(MerchantCategory::class, 'merchant_category_id', 'mer_class_id'); + } + public function merType(){ + return $this->hasOne(MerchantType::class, 'mer_type_id', 'mer_type_id'); + } + public function orderInfo(){ + return $this->hasOne(StoreOrder::class, 'order_id', 'order_id'); + } + + + + +} diff --git a/app/common/repositories/marketing/AgentApplyRepository.php b/app/common/repositories/marketing/AgentApplyRepository.php new file mode 100644 index 0000000..02cdfcb --- /dev/null +++ b/app/common/repositories/marketing/AgentApplyRepository.php @@ -0,0 +1,221 @@ +dao = $dao; + } + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/02/01 14:56 + * @param $search + * @return \app\common\model\marketing\AgentApply + */ + public function getSearchModel($search){ + return $this->dao->searchList($search); + } + /** + * Common: 列表获取 + * Author: wu-hui + * Time: 2024/02/01 15:47 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $params,int $page,int $limit):array{ + $query = $this->dao->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list'); + } + // 提交申请信息(同步生成订单) + public function editApplyInfo($params){ + return Db::transaction(function() use ($params){ + // 生成申请信息 + $applyInfoKeys = array_flip((array)[ + "uid", + "pid", + "agent_type", + "contact_name", + "contact_phone", + "province_id", + "city_id", + "area_id", + "street_id", + "address", + "mer_name", + "mer_class_id", + "mer_type_id", + "mer_images" + ]); + $applyInfo = array_intersect_key($params['data'], $applyInfoKeys); + // 支付信息 + $payInfo = array_intersect_key($params['data'],array_flip((array)["pay_type","return_url"])); + $payResult = []; + // 根据操作类型进行对应的处理 + if($params['agentApplyId'] > 0){ + // 编辑 + + + + + debug("开发中......"); + + return '成功'; + } + else{ + // 添加 是否需要支付 + $payMoney = 0;// 默认 无需支付 + $config = app()->make(AgentRepository::class)->getConfig(); + switch ((int)$applyInfo['agent_type']) { + case 2: $payMoney = $config['province_money'] ?? 0;break; + case 3: $payMoney = $config['field_staff_money'] ?? 0;break; + case 4: $payMoney = $config['internal_staff_money'] ?? 0;break; + case 5: $payMoney = $config['operator_money'] ?? 0;break; + case 6: $payMoney = $config['partner_money'] ?? 0;break; + case 7: $payMoney = $config['mer_money'] ?? 0;break; + case 8: $payMoney = $config['delivery_money'] ?? 0;break; + } + // 判断:是否需要支付 需要支付生成订单并且获取支付信息 + $orderId = 0;// 默认 无需支付、无订单信息 + if((float)$payMoney > 0){ + $userInfo = $params['user_info'] ?? []; + $payInfo['money'] = (float)$payMoney; + // 发起支付 + $groupOrder = app() + ->make(LockService::class) + ->exec('online_order.create',function() use ($payInfo,$userInfo){ + $payType = array_search($payInfo['pay_type'],StoreOrderRepository::PAY_TYPE); + return app() + ->make(StoreOrderCreateRepository::class) + ->onlinePayment($payType,$payInfo,$userInfo, 32); + }); + $payResult = app() + ->make(StoreOrderRepository::class) + ->pay($payInfo['pay_type'],$userInfo,$groupOrder,$payInfo['return_url'],$params['is_app']); + // 子订单只存在一个 直接查询即可 + $orderId = app()->make(StoreOrderRepository::class) + ->getSearch([]) + ->where('group_order_id',$groupOrder->group_order_id) + ->value('order_id'); + } + // 生成申请信息 + $applyInfo['order_id'] = $orderId; + $this->dao->create($applyInfo); + + return $payResult; + } + }); + } + /** + * Common: 审核通过 + * Author: wu-hui + * Time: 2024/02/01 17:10 + * @param $params + * @return mixed + */ + public function toExaminePass($params){ + return Db::transaction(function() use ($params){ + // 修改状态 + $this->dao->update($params['id'],['status'=>$params['status']]); + // 生成代理信息 + $applyInfo = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); + $keys = array_flip((array)[ + "uid", + "pid", + "agent_type", + "contact_name", + "contact_phone", + "province_id", + "city_id", + "area_id", + "street_id", + "address", + ]); + $insertInfo = array_intersect_key($applyInfo, $keys); + $insertInfo['apply_id'] = $applyInfo['id']; + $agentId = Agent::insertGetId($insertInfo); + // 判断:如果是餐厅 生成商户信息 + if((int)$insertInfo['agent_type'] == 7){ + $password = substr($applyInfo['contact_phone'],-6); + $config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']); + $merchant = app()->make(MerchantRepository::class)->createMerchant([ + 'mer_name' => $applyInfo['mer_name'], + 'mer_phone' => $applyInfo['contact_phone'], + 'mer_account' => $applyInfo['contact_phone'], + 'category_id' => $applyInfo['mer_class_id'], + 'type_id' => $applyInfo['mer_type_id'], + 'real_name' => $applyInfo['contact_name'], + 'status' => 1, + 'is_audit' => 1, + 'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1, + 'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1, + 'mer_password' => $password, + 'is_margin' => $margin['is_margin'] ?? -1, + 'margin' => $margin['margin'] ?? 0, + 'agent_id' => $agentId + ]); + // 存在默认管理员信息 生成管理员 + $staffUserInfo = User::where('uid', $applyInfo['uid'])->findOrEmpty()->toArray(); + $staffData = [ + 'uid' => $applyInfo['uid'], + 'nickname' => $staffUserInfo['nickname'] ?? $staffUserInfo['real_name'], + 'account' => $applyInfo['contact_phone'], + 'pwd' => $password, + 'is_open' => 1, + 'status' => 1, + 'customer' => 1, + 'is_verify' => 1, + 'is_goods' => 1, + 'is_user' => 1, + 'staff_manage' => 1, + 'notify' => 1, + 'avatar' => $staffUserInfo['avatar'] ?? '', + 'phone' => $applyInfo['contact_phone'], + 'sort' => 1, + 'mer_id' => $merchant->mer_id, + 'is_manage' => 1 + ]; + app()->make(StoreServiceRepository::class)->createInfo($staffData); + } + + }); + } + + + + + + + + + + + + + + + + +} diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index 036c614..eae547d 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -17,6 +17,17 @@ class AgentRepository extends BaseRepository{ public function __construct(AgentDao $dao){ $this->dao = $dao; } + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/02/01 15:01 + * @param $search + * @return Agent + */ + public function getSearchModel($search){ + return $this->dao->searchList($search); + } + /** * Common: 获取信息列表 * Author: wu-hui @@ -63,17 +74,22 @@ class AgentRepository extends BaseRepository{ /** * Common: 生成对应的二维码 * Author: wu-hui - * Time: 2024/01/29 17:40 - * @param array $data - * @param string $type + * Time: 2024/01/30 18:39 + * @param array $params * @return mixed */ - public function createQrCode(array $data,string $type = 'inviteSupplier'){ + public function createQrCode(array $params){ // 参数获取 - switch($type){ - case 'inviteSupplier': - $valueData = 'agent_id=' . $data['agent_id']; - $path = 'pages/supplier/apply_join'; + switch($params['type']){ + case 'supplier': + $valueData = 'agent_id=' . $params['agent_id']; + $path = 'pages/supplier/apply/apply_join'; + return app()->make(QrcodeService::class)->createQrCode($valueData,$path); + break; + case 'subordinate': + // 参数长度超过 简写:lv=level;agent_id=aid + $valueData = 'lv=' . $params['level'] . '&aid=' . $params['agent_id']; + $path = 'pages/agent/invite/index'; return app()->make(QrcodeService::class)->createQrCode($valueData,$path); break; } @@ -96,7 +112,7 @@ class AgentRepository extends BaseRepository{ // 处理当前角色用户信息 if($agentId > 0) $this->currentRoleHandle($agentId, $data); // 处理子类信息 - if(count($childrenList) > 0) $this->childrenListHandle($agentId, $childrenList); + $this->childrenListHandle($agentId, $childrenList); }); } /** @@ -239,8 +255,68 @@ class AgentRepository extends BaseRepository{ 'children_list' => $childrenList ]; } + /** + * Common: 获取配置 + * Author: wu-hui + * Time: 2024/01/31 14:43 + * @return mixed + */ + public function getConfig(){ + $config = systemConfig([ + 'delivery_money', + 'delivery_money_field_staff', + 'delivery_money_initiator', + 'delivery_money_operator', + 'delivery_money_partner', + 'delivery_money_platform', + 'delivery_money_province', + 'delivery_process', + 'field_staff_money', + 'field_staff_money_initiator', + 'field_staff_money_platform', + 'field_staff_money_province', + 'field_staff_process', + 'internal_staff_money', + 'internal_staff_money_initiator', + 'internal_staff_money_platform', + 'internal_staff_money_province', + 'internal_staff_process', + 'mer_money', + 'mer_money_field_staff', + 'mer_money_initiator', + 'mer_money_operator', + 'mer_money_partner', + 'mer_money_platform', + 'mer_money_province', + 'mer_process', + 'operator_money', + 'operator_money_field_staff', + 'operator_money_initiator', + 'operator_money_platform', + 'operator_money_province', + 'operator_process', + 'partner_money', + 'partner_money_field_staff', + 'partner_money_initiator', + 'partner_money_operator', + 'partner_money_platform', + 'partner_money_province', + 'partner_process', + 'province_money', + 'province_money_initiator', + 'province_money_platform', + 'province_process', + ]); + $config['delivery_process'] = (int)$config['delivery_process']; + $config['field_staff_process'] = (int)$config['field_staff_process']; + $config['internal_staff_process'] = (int)$config['internal_staff_process']; + $config['mer_process'] = (int)$config['mer_process']; + $config['operator_process'] = (int)$config['operator_process']; + $config['partner_process'] = (int)$config['partner_process']; + $config['province_process'] = (int)$config['province_process']; - + return $config; + } } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 99889a6..ea67a28 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -2808,10 +2808,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ }*/ - // 在线买单 - 订单 - public function onlinePayment($payType, $payInfo, $user){ + // 在线买单 - 订单、代理入驻 - 订单 + public function onlinePayment($payType, $payInfo, $user, $activityType = 30){ $payMoney = abs((float)$payInfo['money']); - $merId = (int)$payInfo['mer_id']; + $merId = array_key_exists('mer_id',$payInfo) ? (int)$payInfo['mer_id'] : 0; $uid = $user->uid; // 是否自购 $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; @@ -2825,7 +2825,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ // 整理订单数据 $orderList[] = [ 'cartInfo' => [], - 'activity_type' => 30,// 30=在线买单 + 'activity_type' => $activityType,// 30=在线买单;32=代理入驻 'commission_rate' => 0, 'order_type' => 0, 'is_virtual' => 1, @@ -2849,7 +2849,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'integral' => 0, 'integral_price' => 0, 'give_integral' => 0, - 'mer_id' => $merId, + 'mer_id' => $merId ?? 0, 'cost' => 0, 'order_extend' => '', 'coupon_id' => '', @@ -2878,7 +2878,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'integral' => 0, 'integral_price' => 0, 'give_integral' => 0, - 'activity_type' => 30,// 30=在线买单 + 'activity_type' => $activityType,// 30=在线买单;32=代理入驻 ]; $group = Db::transaction(function() use ($user,$groupOrder,$orderList){ $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 011488a..2cb430d 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -150,6 +150,9 @@ class StoreOrderRepository extends BaseRepository }else if($groupOrder['activity_type'] == 31){ $data['title'] = '酒道馆差价补齐'; $data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元'; + }else if($groupOrder['activity_type'] == 32){ + $data['title'] = '用户申请成为代理人员'; + $data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元'; } $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data); @@ -252,7 +255,7 @@ class StoreOrderRepository extends BaseRepository app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']); } if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode(); - if (!in_array($order->activity_type,[30,31]) && $order->orderProduct[0]->product->type == 2) { + if (!in_array($order->activity_type,[30,31,32]) && $order->orderProduct[0]->product->type == 2) { $order->status = 2; $order->delivery_type = 6; $order->delivery_name = '自动发货'; @@ -260,7 +263,7 @@ class StoreOrderRepository extends BaseRepository $isPoints = true; } // 判断:是否为在线买单、酒道馆补差价 在线买单,订单支付则订单完成 - if(in_array($order->activity_type,[30,31])){ + if(in_array($order->activity_type,[30,31,32])){ $order->status = 3; } diff --git a/app/common/repositories/system/config/ConfigClassifyRepository.php b/app/common/repositories/system/config/ConfigClassifyRepository.php index 07c113d..05d1c57 100644 --- a/app/common/repositories/system/config/ConfigClassifyRepository.php +++ b/app/common/repositories/system/config/ConfigClassifyRepository.php @@ -7,6 +7,7 @@ namespace app\common\repositories\system\config; use app\common\dao\system\config\SystemConfigClassifyDao; +use app\common\model\system\config\SystemConfigClassify; use app\common\repositories\BaseRepository; use FormBuilder\Exception\FormBuilderException; use FormBuilder\Factory\Elm; @@ -104,7 +105,6 @@ class ConfigClassifyRepository extends BaseRepository return $form->setTitle(is_null($id) ? '添加配置分类' : '编辑配置分类')->formData($formData); } - /** * @return Form * @throws FormBuilderException @@ -115,8 +115,6 @@ class ConfigClassifyRepository extends BaseRepository { return $this->form(); } - - /** * @param $id * @return Form @@ -131,4 +129,34 @@ class ConfigClassifyRepository extends BaseRepository { return $this->form($id, $this->dao->get($id)->toArray()); } + + + /** + * Common: 获取配置分类ID 不存在则添加 + * Author: wu-hui + * Time: 2024/01/31 14:27 + * @param $key + * @param $name + * @return int|mixed + */ + public function getConfigClassifyKeyById($key,$name){ + $cid = (int)$this->keyById($key); + // cid小于等于0 添加信息然后返回 + if($cid <= 0){ + $model = new SystemConfigClassify(); + $model->classify_name = $name; + $model->classify_key = $key; + $model->save(); + $cid = $model->config_classify_id; + } + + return $cid; + } + + + + + + + } diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index 343901f..003caff 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -2,8 +2,11 @@ namespace app\controller\admin\marketing; +use app\common\repositories\marketing\AgentApplyRepository; use app\common\repositories\marketing\AgentBrokerageRepository; use app\common\repositories\marketing\AgentRepository; +use app\common\repositories\system\config\ConfigClassifyRepository; +use app\common\repositories\system\config\ConfigValueRepository; use app\common\repositories\system\merchant\MerchantRepository; use crmeb\basic\BaseController; use think\exception\ValidateException; @@ -78,7 +81,7 @@ class Agent extends BaseController{ // 判断:根据当前角色判断 数据 switch((int)$childrenItem['agent_type']){ case 1: - if((float)$childrenItem['agent_stock'] <= 0) throw new ValidateException('发起人的股份必须大于0!'); + // if((float)$childrenItem['agent_stock'] <= 0) throw new ValidateException('发起人的股份必须大于0!'); break; case 2: case 3: @@ -203,8 +206,111 @@ class Agent extends BaseController{ return app('json')->success($data); } + /** + * Common: 申请列表获取 + * Author: wu-hui + * Time: 2024/02/01 15:48 + * @return mixed + */ + public function applyList(){ + $params = $this->request->params(['uid','agent_type','contact_name','contact_phone','mer_name','status']); + [$page, $limit] = $this->getPage(); + $data = app()->make(AgentApplyRepository::class)->getList($params, $page, $limit); + + return app('json')->success($data); + } + /** + * Common: 审核 + * Author: wu-hui + * Time: 2024/02/01 18:00 + * @return mixed + */ + public function toExamine(){ + // 参数获取 + $params = $this->request->params(['id','status','reason']); + if($params['id'] <= 0) throw new ValidateException('方法请求,信息不明确!'); + // 审核通过 主动生成账号 + if((int)$params['status'] === 1){ + // 审核通过 + app()->make(AgentApplyRepository::class)->toExaminePass((array)$params); + }else{ + // 驳回 + app()->make(AgentApplyRepository::class)->update($params['id'],['status'=>$params['status'],'reason'=>$params['reason']]); + } + + return app('json')->success('操作成功'); + } + /** + * Common: 配置信息 - 修改配置信息 + * Author: wu-hui + * Time: 2024/01/31 14:15 + * @return mixed + */ + public function setConfig(){ + $config = $this->request->params([ + ['delivery_money',0], + ['delivery_money_field_staff',0], + ['delivery_money_initiator',0], + ['delivery_money_operator',0], + ['delivery_money_partner',0], + ['delivery_money_platform',0], + ['delivery_money_province',0], + ['delivery_process',0], + ['field_staff_money',0], + ['field_staff_money_initiator',0], + ['field_staff_money_platform',0], + ['field_staff_money_province',0], + ['field_staff_process',0], + ['internal_staff_money',0], + ['internal_staff_money_initiator',0], + ['internal_staff_money_platform',0], + ['internal_staff_money_province',0], + ['internal_staff_process',0], + ['mer_money',0], + ['mer_money_field_staff',0], + ['mer_money_initiator',0], + ['mer_money_operator',0], + ['mer_money_partner',0], + ['mer_money_platform',0], + ['mer_money_province',0], + ['mer_process',0], + ['operator_money',0], + ['operator_money_field_staff',0], + ['operator_money_initiator',0], + ['operator_money_platform',0], + ['operator_money_province',0], + ['operator_process',0], + ['partner_money',0], + ['partner_money_field_staff',0], + ['partner_money_initiator',0], + ['partner_money_operator',0], + ['partner_money_platform',0], + ['partner_money_province',0], + ['partner_process',0], + ['province_money',0], + ['province_money_initiator',0], + ['province_money_platform',0], + ['province_process',0], + ]); + // 保存信息 + $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('agent_config', '代理中心配置'); + if (!$cid) return app('json')->fail('保存失败'); + app()->make(ConfigValueRepository::class)->setFormData($config,$this->request->merId()); + return app('json')->success('保存成功'); + } + /** + * Common: 配置信息 - 获取配置信息 + * Author: wu-hui + * Time: 2024/01/31 14:32 + * @return mixed + */ + public function getConfig(){ + $config = app()->make(AgentRepository::class)->getConfig(); + + return app('json')->success($config); + } /** * Common: 佣金列表 * Author: wu-hui @@ -218,15 +324,4 @@ class Agent extends BaseController{ return app('json')->success($data); } - - - - - - - - - - - } diff --git a/app/controller/api/Agent.php b/app/controller/api/Agent.php index 4234f2c..a484c54 100644 --- a/app/controller/api/Agent.php +++ b/app/controller/api/Agent.php @@ -3,10 +3,12 @@ namespace app\controller\api; +use app\common\model\system\merchant\Merchant; +use app\common\repositories\marketing\AgentApplyRepository; use app\common\repositories\marketing\AgentRepository; use crmeb\basic\BaseController; use think\App; - +use think\exception\ValidateException; class Agent extends BaseController{ @@ -41,14 +43,10 @@ class Agent extends BaseController{ */ public function qrCodeInviteSupplier(){ // 参数获取 - $agentId = (int)$this->request->param('agent_id'); - if((int)$agentId > 0){ - $qrcode = $this->repository->createQrCode(['agent_id'=>$agentId]); + $params = $this->request->params(['agent_id','type','level']); + $qrcode = $this->repository->createQrCode($params); - return app('json')->success(['qr_code' => $qrcode]); - } - - return app('json')->fail('小程序码生成失败!'); + return app('json')->success(['qr_code' => $qrcode]); } /** * Common: 获取单条代理人员信息 @@ -62,10 +60,145 @@ class Agent extends BaseController{ return app('json')->success($res); } + /** + * Common: 获取配置信息 + * Author: wu-hui + * Time: 2024/01/31 15:49 + * @return mixed + */ + public function getConfig(){ + $config = app()->make(AgentRepository::class)->getConfig(); + + return app('json')->success($config); + } + /** + * Common: 申请成为代理 + * Author: wu-hui + * Time: 2024/02/01 15:14 + * @return mixed + */ + public function apply(){ + // 获取申请参数 + $params = $this->applyCheckParams(); + // 处理数据 + $params['user_info'] = $this->request->userInfo(); + $params['is_app'] = $this->request->isApp(); + + $res = app()->make(AgentApplyRepository::class)->editApplyInfo($params); + + if($res) return $res; + else return app('json')->success("操作成功"); + } + /** + * Common: 申请参数获取 & 参数校验 + * Author: wu-hui + * Time: 2024/02/01 13:41 + * @return array + */ + public function applyCheckParams():array{ + // 参数获取 + $agentApplyId = (int)$this->request->param('id'); + $data = $this->request->params([ + ['pid',0], + ['agent_type',0], + 'contact_name', + 'contact_phone', + ['province_id',0], + ['city_id', 0], + ['area_id', 0], + ['street_id', 0], + 'address', + ['mer_name', ''], + ['mer_class_id', 0], + ['mer_type_id', 0], + ['mer_images', []], + // 支付相关 + 'pay_type', + 'return_url' + ]); + $data['uid'] = $this->request->uid(); + // 信息验证 + if((int)$data['pid'] <= 0) throw new ValidateException('非法请求,无邀请信息!'); + if(!in_array((int)$data['agent_type'], [2,3,4,5,6,7,8])) throw new ValidateException('非法请求,代理类型错误!'); + if(empty($data['contact_name'])) throw new ValidateException('请输入联系人姓名!'); + if(empty($data['contact_phone'])) throw new ValidateException('请输入联系人电话!'); + if((int)$data['province_id'] <= 0) throw new ValidateException('请选择地区!'); + if(in_array((int)$data['agent_type'], [5,6,7])){ + if((int)$data['city_id'] <= 0) throw new ValidateException('请选择地区!'); + if((int)$data['area_id'] <= 0) throw new ValidateException('请选择地区!'); + } + if((int)$data['agent_type'] == 7){ + if((int)$data['street_id'] <= 0) throw new ValidateException('请选择地区!'); + if(empty($data['address'])) throw new ValidateException('请输入详细地址!'); + if(empty($data['mer_name'])) throw new ValidateException('请输入商户名称!'); + if((int)$data['mer_class_id'] <= 0) throw new ValidateException('请选择商户分类!'); + if((int)$data['mer_type_id'] <= 0) throw new ValidateException('请选择商户类型!'); + if(count($data['mer_images']) <= 0) throw new ValidateException('请上传资质证明图片!'); + // 判断:商户名称是否重复 + $merHas = Merchant::where('mer_name',$data['mer_name'])->count(); + if($merHas > 0) throw new ValidateException('商户已经存在!'); + // 判断:商户名称是否重复 + $isHas = app()->make(AgentApplyRepository::class) + ->getSearchModel([]) + ->where('mer_name', $data['mer_name']) + ->when($agentApplyId > 0,function($query) use ($agentApplyId){ + $query->where('id','!=',$agentApplyId); + }) + ->count(); + if($isHas > 0) throw new ValidateException('商户已经存在,请勿重复申请!'); + } + // 信息是否重复 + $isHas = (int)app()->make(AgentApplyRepository::class) + ->getSearchModel(['contact_phone'=>$data['contact_phone']]) + ->when($agentApplyId > 0,function($query) use ($agentApplyId){ + $query->where('id','!=',$agentApplyId); + })->count(); + if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!'); + $isHas = (int)$this->repository + ->getSearchModel(['contact_phone'=>$data['contact_phone']]) + ->count(); + if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!'); + // 不能 重复成为当前等级的用户 + $isHas = (int)$this->repository + ->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']]) + ->count(); + if($isHas > 0) throw new ValidateException('代理身份信息已经存在!'); + $isHas = (int)app()->make(AgentApplyRepository::class) + ->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']]) + ->when($agentApplyId > 0,function($query) use ($agentApplyId){ + $query->where('id','!=',$agentApplyId); + })->count(); + if($isHas > 0) throw new ValidateException('代理身份信息已经存在,请勿重复申请!'); + return compact("agentApplyId", "data"); + } + /** + * Common: 获取申请记录 + * Author: wu-hui + * Time: 2024/02/01 18:02 + * @return mixed + */ + public function applyRecord(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params([]); + $params['uid'] = $this->request->uid(); + $data = app()->make(AgentApplyRepository::class)->getList((array)$params,(int)$page,(int)$limit); + return app('json')->success($data); + } + /** + * Common: 单条申请信息 + * Author: wu-hui + * Time: 2024/02/01 18:27 + * @return mixed + */ + public function applyInfo(){ + $applyId = $this->request->param('apply_id'); + $data = app()->make(AgentApplyRepository::class)->getSearchModel(['id'=>$applyId])->findOrEmpty()->toArray(); + return app('json')->success($data); + } } diff --git a/app/controller/api/Supplier.php b/app/controller/api/Supplier.php index 4187618..8c35455 100644 --- a/app/controller/api/Supplier.php +++ b/app/controller/api/Supplier.php @@ -29,7 +29,7 @@ class Supplier extends BaseController{ $data = $this->checkParam(); if((int)$data['supplierApplyId'] > 0){ // 编辑账号信息 - app()->make(SystemSupplierApplyServices::class)->editInfo((array)$data); + app()->make(SystemSupplierApplyServices::class)->editApplyInfo((array)$data); }else{ // 添加账号 app()->make(SystemSupplierApplyServices::class)->createApplyInfo((array)$data); @@ -63,6 +63,7 @@ class Supplier extends BaseController{ 'production_icense', 'circulative_license', ]); + $applyInfo['uid'] = $this->request->uid(); // 数据校验 if (empty($applyInfo['invite_agent_id'])) throw new ValidateException('非法请求,无有效邀请人!'); if (empty($applyInfo['winery_name'])) throw new ValidateException('请输入酒厂名称!'); @@ -83,12 +84,20 @@ class Supplier extends BaseController{ if (empty($applyInfo['production_icense'])) throw new ValidateException('请上传生产许可证!'); if (empty($applyInfo['circulative_license'])) throw new ValidateException('请上传流通许可证!'); // 联系人及联系人手机号 - $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['contacts_phone'=>$applyInfo['contacts_phone']])->count(); + $isHas = app()->make(SystemSupplierApplyServices::class) + ->searchModel(['contacts_phone'=>$applyInfo['contacts_phone']]) + ->when($supplierApplyId > 0,function($query) use ($supplierApplyId){ + $query->where('id','<>', $supplierApplyId); + }) + ->count(); if($isHas >= 1) throw new ValidateException('联系人已经存在,请勿重复申请!'); // 酒厂是否已经存在 - $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['winery_name'=>$applyInfo['winery_name']])->count(); - if($isHas >= 1) throw new ValidateException('酒厂已经存在,请勿重复申请!'); - $isHas = app()->make(SystemSupplierApplyServices::class)->searchModel(['winery_name'=>$applyInfo['winery_name']])->count(); + $isHas = app()->make(SystemSupplierApplyServices::class) + ->searchModel(['winery_name'=>$applyInfo['winery_name']]) + ->when($supplierApplyId > 0,function($query) use ($supplierApplyId){ + $query->where('id','<>', $supplierApplyId); + }) + ->count(); if($isHas >= 1) throw new ValidateException('酒厂已经存在,请勿重复申请!'); $nameIsHave = $this->services->isHave('supplier_name',$applyInfo['winery_name']); if($nameIsHave) throw new ValidateException('该酒厂已经入驻,请勿重复申请!'); @@ -96,6 +105,33 @@ class Supplier extends BaseController{ return compact('supplierApplyId','applyInfo'); } + /** + * Common: 申请记录 + * Author: wu-hui + * Time: 2024/01/30 17:11 + * @return mixed + */ + public function applyRecord(){ + $search = $this->request->params(['winery_name','contacts_name','contacts_phone','invite_agent_id','status']); + $search['uid'] = $this->request->uid(); + [$page, $limit] = $this->getPage(); + $data = app()->make(SystemSupplierApplyServices::class)->getList($search, $page, $limit); + + return app('json')->success($data); + } + /** + * Common: 获取单条申请信息 + * Author: wu-hui + * Time: 2024/01/30 17:35 + * @return mixed + */ + public function applyInfo(){ + $applyId = $this->request->param('apply_id'); + $data = app()->make(SystemSupplierApplyServices::class)->getSingleInfo(['id'=>$applyId]); + + return app('json')->success($data); + } + } diff --git a/app/dao/supplier/SystemSupplierApplyDao.php b/app/dao/supplier/SystemSupplierApplyDao.php index 2ca4e72..54f0647 100644 --- a/app/dao/supplier/SystemSupplierApplyDao.php +++ b/app/dao/supplier/SystemSupplierApplyDao.php @@ -17,6 +17,9 @@ class SystemSupplierApplyDao extends BaseDao{ ->when(isset($search['id']) && $search['id'] !== '',function($query) use ($search){ $query->where('id',$search['id']); }) + ->when(isset($search['uid']) && $search['uid'] !== '',function($query) use ($search){ + $query->where('uid',$search['uid']); + }) ->when(isset($search['contacts_phone']) && $search['contacts_phone'] !== '',function($query) use ($search){ $query->where('contacts_phone',$search['contacts_phone']); }) diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 7d826f6..f44556c 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -25,8 +25,10 @@ class OrderPaySuccessEvent{ // 在线支付订单 $this->giveExchangeIntegral($groupOrder); }else if($groupOrder->activity_type == 31){ - // 在线支付订单 + // 兑换商品补差价处理 $this->exchangeGoodsHandle($groupOrder); + }else if($groupOrder->activity_type == 32){ + // 代理入驻支付 }else{ // 其他订单 $this->orderPaySuccessHandle($groupOrder); diff --git a/app/model/supplier/SystemSupplierApply.php b/app/model/supplier/SystemSupplierApply.php index 340a290..acb146f 100644 --- a/app/model/supplier/SystemSupplierApply.php +++ b/app/model/supplier/SystemSupplierApply.php @@ -22,10 +22,14 @@ class SystemSupplierApply extends BaseModel{ return implode(',',$value); } public function getCorporationIdCardAttr($value){ - return explode(',',$value); + if(!empty($value)) return explode(',',$value); + + return []; } public function getChairmanIdCardAttr($value){ - return explode(',',$value); + if(!empty($value)) return explode(',',$value); + + return []; } diff --git a/app/services/supplier/SystemSupplierApplyServices.php b/app/services/supplier/SystemSupplierApplyServices.php index 5d34a6b..4e96e39 100644 --- a/app/services/supplier/SystemSupplierApplyServices.php +++ b/app/services/supplier/SystemSupplierApplyServices.php @@ -46,6 +46,16 @@ class SystemSupplierApplyServices extends BaseServices{ return compact('count', 'list'); } + /** + * Common: 获取单条信息 + * Author: wu-hui + * Time: 2024/01/30 17:34 + * @param $search + * @return array + */ + public function getSingleInfo($search){ + return $this->dao->searchModel($search)->findOrEmpty()->toArray(); + } /** * Common: 添加申请信息 * Author: wu-hui @@ -55,13 +65,31 @@ class SystemSupplierApplyServices extends BaseServices{ */ public function createApplyInfo(array $data){ return $this->transaction(function() use ($data){ - // 添加供应商信息 + // 添加供应商申请信息 $relation_id = $this->dao->save($data['applyInfo'])->id; if(!$relation_id) throw new AdminException('申请失败'); return $relation_id; }); } + /** + * Common: 修改编辑信息 + * Author: wu-hui + * Time: 2024/01/30 18:07 + * @param array $data + * @return mixed + */ + public function editApplyInfo(array $data){ + return $this->transaction(function() use ($data){ + // 修改供应商申请信息 + $data['applyInfo']['status'] = 0; + $data['applyInfo']['reason'] = ''; + $res = $this->dao->update($data['supplierApplyId'],$data['applyInfo']); + if(!$res) throw new AdminException('申请信息修改失败'); + + return true; + }); + } /** * Common: 审核通过的操作 * Author: wu-hui diff --git a/route/admin/marketing.php b/route/admin/marketing.php index dbab205..8350eba 100644 --- a/route/admin/marketing.php +++ b/route/admin/marketing.php @@ -465,7 +465,7 @@ Route::group(function () { ]); // 代理中心 Route::group('marketing/agent', function () { - // 代理商相关 + // 代理管理相关 Route::get('list','/agentList')->name('systemMarketingAgentList')->option([ '_alias' => '代理列表', ]); @@ -475,13 +475,30 @@ Route::group(function () { Route::get('get_edit_info','/getEditInfo')->name('systemMarketingAgentGetEditInfo')->option([ '_alias' => '获取编辑信息', ]); - // 代理商佣金明细 + // 申请审核 + Route::get('apply_list', '/applyList')->name('systemMarketingAgentApplyList')->option([ + '_alias' => '代理申请列表', + ]); + Route::post('apply_to_examine', '/toExamine')->name('systemMarketingAgentToExamine')->option([ + '_alias' => '代理申请审核', + ]); + + + + + // 代理配置相关 + Route::post('config','/setConfig')->name('systemMarketingAgentSetConfig')->option([ + '_alias' => '设置配置信息', + ]); + Route::get('config','/getConfig')->name('systemMarketingAgentGetConfig')->option([ + '_alias' => '获取配置信息', + ]); + // 代理佣金明细 Route::get('commission_list','/commissionList')->name('systemMarketingAgentCommissionList')->option([ '_alias' => '佣金明细', ]); - })->prefix('admin.marketing.Agent')->option([ '_path' => '/marketing/agent/list', '_auth' => true, diff --git a/route/api.php b/route/api.php index 572ffd9..45f1076 100644 --- a/route/api.php +++ b/route/api.php @@ -389,6 +389,8 @@ Route::group('api/', function () { Route::get('single_agent_info/:id', 'singleAgentInfo');// 获取单个代理人员信息 Route::get('get_config', 'getConfig');// 获取配置信息 Route::post('agent_apply', 'apply');// 提交申请信息 + Route::post('apply_record', 'applyRecord');// 申请记录 + Route::post('apply_info', 'applyInfo');// 申请记录