第一次更新,完成了初版调整
This commit is contained in:
@@ -64,40 +64,8 @@ class User extends Controller
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new UserModel;
|
||||
$data = $this->postForm();
|
||||
if (empty($data['company_id'])) {
|
||||
return $this->renderError('请填写分油公司');
|
||||
}
|
||||
if (empty($data['merchant_id'])) {
|
||||
return $this->renderError('请填写商户');
|
||||
}
|
||||
if (empty($data['userType'])) {
|
||||
return $this->renderError('请填写用户角色');
|
||||
}
|
||||
if (empty($data['userName'])) {
|
||||
return $this->renderError('请填写用户姓名');
|
||||
}
|
||||
if (empty($data['mobile'])) {
|
||||
return $this->renderError('请填写用户手机号');
|
||||
}
|
||||
if (empty($data['userIdCard'])) {
|
||||
return $this->renderError('请填写用户身份证号');
|
||||
}
|
||||
|
||||
$company = CompanyModel::detail($data['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $this->userOptAdd(['mobile'=>$data['mobile'],'userName'=>$data['userName'],'userIdCard'=>$data['userIdCard'],'userType'=>$data['userType']], $company);
|
||||
if($res['code'] == '00' && isset($res['data']['userNo'])){
|
||||
$data['userNo'] = $res['data']['userNo'];
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
// 新增记录
|
||||
if ($model->add($data,$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
// 企油通改造:分油用户池已停用(司机信息改由下单平台随单传入),不再向上游注册用户。
|
||||
return $this->renderError('分油用户池已停用');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,80 +169,8 @@ class User extends Controller
|
||||
*/
|
||||
public function oil(int $userId, string $target)
|
||||
{
|
||||
$data = $this->postForm();
|
||||
$user = UserModel::detail($userId);
|
||||
$data['amount'] = $data['amount']??0;
|
||||
$data['goodsNo'] = $data['goodsNo']??'';
|
||||
// 用户详情
|
||||
$model = new OrderModel();
|
||||
if (empty($data['oilCardType'])) {
|
||||
return $this->renderError('请填写卡券类型');
|
||||
}
|
||||
if ($data['oilCardType'] == 'card' && empty($data['amount'])) {
|
||||
return $this->renderError('请填写分油金额');
|
||||
}
|
||||
if ($data['oilCardType'] != 'card' && empty($data['goods_id'])) {
|
||||
return $this->renderError('请选择油券');
|
||||
}
|
||||
if($data['goods_id']) {
|
||||
$goods = GoodsModel::detail($data['goods_id']);
|
||||
$data['goodsNo'] = $goods['goods_no'];
|
||||
$data['amount'] = $goods['goods_price_max']; // 金额
|
||||
}
|
||||
// 查询用户余额
|
||||
if($data['amount'] > $user['balance']){
|
||||
return $this->renderError('用户余额不足');
|
||||
}
|
||||
$saleOrderNo = OrderService::createOrderNo();
|
||||
try {
|
||||
// 查找一个未被调用的用户
|
||||
$account = $this->processUserOrders();
|
||||
} catch (Exception $e) {
|
||||
return $this->renderError($e->getMessage());
|
||||
}
|
||||
$company = CompanyModel::detail($account['company_id']);
|
||||
// 查询公司余额
|
||||
if($data['amount'] > $company['balance']){
|
||||
return $this->renderError('公司余额不足');
|
||||
}
|
||||
$SybOil = new SybOil();
|
||||
// 对接平台接口
|
||||
$res = $SybOil->oilOilCardShare(['goodsNo'=>$data['goodsNo'],'amount'=>$data['amount'],'userNo'=>$account['userNo'],'mobile'=>$account['mobile'],'saleOrderNo'=>$saleOrderNo,'oilCardType'=>$data['oilCardType']], $company);
|
||||
//$res = json_decode('{"code":"00","message":"请求成功","errCode":null,"errMessage":null,"data":{"oilCardNo":null,"amount":100,"balance":null,"shareNo":"CDV2407271355570001"}}',true);
|
||||
if($res['code'] == '00'){
|
||||
$data['saleOrderNo'] = $saleOrderNo;
|
||||
$data['oilCardNo'] = $data['oilCardType'] == 'zsy_ticket' ? $res['data']['shareNo'] : $res['data']['oilCardNo'];
|
||||
$data['amount'] = $res['data']['amount'];
|
||||
$data['shareNo'] = $res['data']['shareNo'] ?? '';
|
||||
$data['company_id'] = $account['company_id'];
|
||||
$data['account_id'] = $account['account_id'];
|
||||
$data['userNo'] = $account['userNo'];
|
||||
$data['mobile'] = $account['mobile'];
|
||||
}else{
|
||||
return $this->renderError('平台分油失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
$data['user_id'] = $user['user_id'];
|
||||
$data['store_id'] = $user['store_id'];
|
||||
$data['payType'] = 10;
|
||||
if ($model->addOil($data)) {
|
||||
// 更新用户余额
|
||||
UserModel::setDecBalance((int)$user['user_id'], (float)$data['amount']);
|
||||
BalanceLogModel::add(SceneEnum::CONSUME, [
|
||||
'user_id' => (int)$user['user_id'],
|
||||
'money' => -(float)$data['amount'],
|
||||
], ['saleOrderNo' => $saleOrderNo]);
|
||||
// 累积用户总消费金额
|
||||
UserModel::setIncPayMoney($user['user_id'], (float)$data['amount']);
|
||||
|
||||
// 更新公司余额
|
||||
CompanyModel::setDecBalance((int)$user['company_id'], (float)$data['amount']);
|
||||
CompanyBalanceLogModel::add(SceneEnum::CONSUME, [
|
||||
'company_id' => (int)$user['company_id'],
|
||||
'money' => -(float)$data['amount'],
|
||||
], ['saleOrderNo' => $saleOrderNo]);
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
// 企油通改造:后台给小程序用户手动分油依赖已下线的上游(智慧油客)+ 分油用户池,现已停用。
|
||||
return $this->renderError('小程序油品链路已停用');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user