216 lines
8.7 KiB
PHP
216 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace app\common\repositories\marketing;
|
|
|
|
use app\common\dao\marketing\AgentApplyDao;
|
|
use app\common\model\marketing\Agent;
|
|
use app\common\model\user\User;
|
|
use app\common\repositories\BaseRepository;
|
|
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
use app\common\repositories\store\service\StoreServiceRepository;
|
|
use app\common\repositories\system\merchant\MerchantRepository;
|
|
use crmeb\services\LockService;
|
|
use think\facade\Db;
|
|
|
|
class AgentApplyRepository extends BaseRepository{
|
|
|
|
protected $dao;
|
|
|
|
public function __construct(AgentApplyDao $dao){
|
|
$this->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');
|
|
}
|
|
/**
|
|
* Common: 提交申请信息(同步生成订单)
|
|
* Author: wu-hui
|
|
* Time: 2024/02/02 11:21
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
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",
|
|
'enterprise_name'
|
|
]);
|
|
$applyInfo = array_intersect_key($params['data'], $applyInfoKeys);
|
|
$applyInfo['mer_images'] = implode(',',$applyInfo['mer_images']);
|
|
// 支付信息
|
|
$payInfo = array_intersect_key($params['data'],array_flip((array)["pay_type","return_url"]));
|
|
$payResult = [];
|
|
// 根据操作类型进行对应的处理
|
|
if($params['agentApplyId'] > 0){
|
|
// 编辑
|
|
$applyInfo['status'] = 0;
|
|
$applyInfo['reason'] = '';
|
|
|
|
$this->dao->update($params['agentApplyId'], $applyInfo);
|
|
}
|
|
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::update(['mer_id'=>$merchant->mer_id],['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);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|