feat: 修改用户和订单相关逻辑

This commit is contained in:
mkm 2024-06-18 10:12:36 +08:00
parent 5768afd77a
commit a08d9ff067
2 changed files with 53 additions and 95 deletions

View File

@ -77,7 +77,7 @@ class UserLogic extends BaseLogic
try { try {
$data=[ $data=[
'avatar' => $avatar, 'avatar' => $avatar,
'real_name' =>'', 'real_name' => $params['real_name']??"",
'nickname' => '用户'.time(), 'nickname' => '用户'.time(),
'account' => $params['mobile'], 'account' => $params['mobile'],
'password' => $password, 'password' => $password,
@ -88,7 +88,7 @@ class UserLogic extends BaseLogic
$res=User::create($data); $res=User::create($data);
UserAddress::create([ UserAddress::create([
'uid' => $res['id'], 'uid' => $res['id'],
'real_name' => $data['nickname'], 'real_name' => $params['real_name']??"",
'mobile' => $params['mobile'], 'mobile' => $params['mobile'],
'province' => $params['province'], 'province' => $params['province'],
'city' => $params['city'], 'city' => $params['city'],

View File

@ -35,41 +35,7 @@ use Webman\RedisQueue\Redis;
class StoreOrderController extends BaseAdminController class StoreOrderController extends BaseAdminController
{ {
// #[ /**订单列表 */
// ApiDoc\Title('订单列表'),
// ApiDoc\url('/store/store_order/storeOrder/lists'),
// ApiDoc\Method('GET'),
// ApiDoc\NotHeaders(),
// ApiDoc\Author('中国队长'),
// ApiDoc\Query(name: 'order_id', type: 'string', require: false, desc: '订单编号'),
// ApiDoc\Query(name: 'staff_id', type: 'int', require: false, desc: '店员id'),
// ApiDoc\Query(name: 'delivery_phone', type: 'int', require: false, desc: '配送员手机号'),
// ApiDoc\Query(name: 'shipping_type', type: 'int', require: false, desc: '订单配送方式1配送订单2核销订单3收银台订单'),
// ApiDoc\Query(name: 'start_time', type: 'string', require: false, desc: '开始时间'),
// ApiDoc\Query(name: 'end_time', type: 'string', require: false, desc: '结束时间'),
// ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态:-1待支付0待发货1待收货2已完成'),
// ApiDoc\Header(ref: [Definitions::class, "token"]),
// ApiDoc\Query(ref: [Definitions::class, "page"]),
// ApiDoc\ResponseSuccess("data", type: "array", children: [
// ['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
// ['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'],
// ['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'],
// ['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'],
// ['name' => 'pay_type', 'desc' => '支付方式', 'type' => 'float'],
// ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'],
// ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'],
// ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'],
// ['name' => 'avatar', 'desc' => '用户头像', 'type' => 'string'],
// ['name' => 'product', 'desc' => '商品信息', 'type' => 'array', 'children' => [
// ['name' => 'cart_info', 'desc' => '商品信息', 'type' => 'array', 'children' => [
// ['name' => 'name', 'desc' => '商品名称', 'type' => 'int'],
// ['name' => 'image', 'desc' => '图片', 'type' => 'string'],
// ['name' => 'cart_num', 'desc' => '购买数量', 'type' => 'string'],
// ['name' => 'price', 'desc' => '单价', 'type' => 'string'],
// ]],
// ]],
// ]),
// ]
public function lists() public function lists()
{ {
return $this->dataLists(new StoreOrderLists()); return $this->dataLists(new StoreOrderLists());
@ -98,17 +64,9 @@ class StoreOrderController extends BaseAdminController
]); ]);
} }
// #[ /**
// ApiDoc\Title('订单详情'), * 订单详情
// ApiDoc\url('/store/store_order/storeOrder/detail'), */
// ApiDoc\Method('GET'),
// ApiDoc\NotHeaders(),
// ApiDoc\Author('中国队长'),
// ApiDoc\Header(ref: [Definitions::class, "token"]),
// ApiDoc\Query(name: 'id', type: 'int', require: false, desc: '订单id'),
// ApiDoc\Query(name: 'verify_code', type: 'string', require: false, desc: '核销码'),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function detail(StoreOrderLogic $orderLogic) public function detail(StoreOrderLogic $orderLogic)
{ {
$params = (new StoreOrderValidate())->goCheck('detail'); $params = (new StoreOrderValidate())->goCheck('detail');
@ -116,11 +74,14 @@ class StoreOrderController extends BaseAdminController
return $this->data($result); return $this->data($result);
} }
/**
* 订单检查
*/
public function checkOrder() public function checkOrder()
{ {
$cartId = (array)$this->request->post('cart_id', []); $cartId = (array)$this->request->post('cart_id', []);
$params = $this->request->post(); $params = $this->request->post();
$params['store_id']=$this->adminInfo['store_id']; $params['store_id'] = $this->adminInfo['store_id'];
$res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, null, $params); $res = StoreOrderLogic::cartIdByOrderInfo($cartId, null, null, $params);
if ($res == false) { if ($res == false) {
$msg = StoreOrderLogic::getError(); $msg = StoreOrderLogic::getError();
@ -137,24 +98,23 @@ class StoreOrderController extends BaseAdminController
{ {
$params = (new StoreOrderValidate())->post()->goCheck('check'); $params = (new StoreOrderValidate())->post()->goCheck('check');
$params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单 $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单
$user= User::where('id',$params['uid'])->find(); $user = User::where('id', $params['uid'])->find();
if(empty($user)){ if (empty($user)) {
return $this->fail('无该用户请检查'); return $this->fail('无该用户请检查');
} }
$order = StoreOrderLogic::cartIdByOrderInfo($params['cart_id'], null, $user, $params); $order = StoreOrderLogic::cartIdByOrderInfo($params['cart_id'], null, $user, $params);
if(!$order){ if (!$order) {
return $this->fail(StoreOrderLogic::getError()); return $this->fail(StoreOrderLogic::getError());
} }
if($order['order']['pay_price'] > $user['purchase_funds']){ if ($order['order']['pay_price'] > $user['purchase_funds']) {
return $this->fail('当前用户采购款不足支付'); return $this->fail('当前用户采购款不足支付');
} }
$res = (new StoreOrderLogic())->dealSendSms($params); $res = (new StoreOrderLogic())->dealSendSms($params);
if($res){ if ($res) {
return $this->success('发送成功',[],1,0); return $this->success('发送成功', [], 1, 0);
}else{ } else {
return $this->fail('发送失败'); return $this->fail('发送失败');
} }
} }
@ -175,8 +135,8 @@ class StoreOrderController extends BaseAdminController
return $this->fail('购物车商品不能超过100个'); return $this->fail('购物车商品不能超过100个');
} }
$user = null; $user = null;
if($pay_type == PayEnum::PURCHASE_FUNDS){ if ($pay_type == PayEnum::PURCHASE_FUNDS) {
$user = User::where('id',$this->request->post('uid'))->find(); $user = User::where('id', $this->request->post('uid'))->find();
} }
$params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单 $params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id用于判断是否是当前店铺的订单
$order = StoreOrderLogic::createOrder($cartId, $addressId, $user, $params); $order = StoreOrderLogic::createOrder($cartId, $addressId, $user, $params);
@ -184,13 +144,13 @@ class StoreOrderController extends BaseAdminController
switch ($pay_type) { switch ($pay_type) {
case PayEnum::PURCHASE_FUNDS: case PayEnum::PURCHASE_FUNDS:
//采购款支付 //采购款支付
PayNotifyLogic::handle('purchase_funds', $order['order_id'],['uid'=>$this->request->post('uid')]); PayNotifyLogic::handle('purchase_funds', $order['order_id'], ['uid' => $this->request->post('uid')]);
return $this->success('采购款支付成功',['id'=>$order['id']]); return $this->success('采购款支付成功', ['id' => $order['id']]);
case PayEnum::CASH_PAY: case PayEnum::CASH_PAY:
//现金支付 //现金支付
PayNotifyLogic::handle('cash_pay', $order['order_id']); PayNotifyLogic::handle('cash_pay', $order['order_id']);
return $this->success('现金支付成功',['id'=>$order['id']]); return $this->success('现金支付成功', ['id' => $order['id']]);
case PayEnum::WECHAT_PAY_BARCODE: case PayEnum::WECHAT_PAY_BARCODE:
//微信条码支付 //微信条码支付
@ -205,7 +165,7 @@ class StoreOrderController extends BaseAdminController
Redis::send('send-code-pay', ['order_id' => $order['order_id']]); Redis::send('send-code-pay', ['order_id' => $order['order_id']]);
return $this->success('用户支付中'); return $this->success('用户支付中');
} }
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id'],'id'=>$order['id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id'], 'id' => $order['id']]);
case PayEnum::ALIPAY_BARCODE: case PayEnum::ALIPAY_BARCODE:
//支付宝条码支付 //支付宝条码支付
$result = PaymentLogic::ali_auth_code($auth_code, $order); $result = PaymentLogic::ali_auth_code($auth_code, $order);
@ -217,7 +177,7 @@ class StoreOrderController extends BaseAdminController
} }
PayNotifyLogic::handle('alipay_cashier', $result['out_trade_no'], $result); PayNotifyLogic::handle('alipay_cashier', $result['out_trade_no'], $result);
$result['create_time'] = $order['create_time']; $result['create_time'] = $order['create_time'];
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no'],'id'=>$order['id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no'], 'id' => $order['id']]);
default: default:
return $this->fail('支付方式错误'); return $this->fail('支付方式错误');
} }
@ -252,7 +212,7 @@ class StoreOrderController extends BaseAdminController
case PayEnum::CASH_PAY: case PayEnum::CASH_PAY:
//现金支付 //现金支付
PayNotifyLogic::handle('cash_pay', $order['order_id']); PayNotifyLogic::handle('cash_pay', $order['order_id']);
return $this->success('现金支付成功',['id'=>$order['id']]); return $this->success('现金支付成功', ['id' => $order['id']]);
break; break;
case PayEnum::WECHAT_PAY_BARCODE: case PayEnum::WECHAT_PAY_BARCODE:
//微信条码支付 //微信条码支付
@ -266,7 +226,7 @@ class StoreOrderController extends BaseAdminController
Redis::send('send-code-pay', ['order_id' => $order['order_id']]); Redis::send('send-code-pay', ['order_id' => $order['order_id']]);
return $this->success('用户支付中'); return $this->success('用户支付中');
} }
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id'],'id'=>$order['id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id'], 'id' => $order['id']]);
case PayEnum::ALIPAY_BARCODE: case PayEnum::ALIPAY_BARCODE:
//支付宝条码支付 //支付宝条码支付
$result = PaymentLogic::ali_auth_code($auth_code, $order); $result = PaymentLogic::ali_auth_code($auth_code, $order);
@ -279,7 +239,7 @@ class StoreOrderController extends BaseAdminController
PayNotifyLogic::handle('alipay_cashier', $result['out_trade_no'], $result); PayNotifyLogic::handle('alipay_cashier', $result['out_trade_no'], $result);
$result['create_time'] = $order['create_time']; $result['create_time'] = $order['create_time'];
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no'],'id'=>$order['id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no'], 'id' => $order['id']]);
default: default:
return $this->fail('支付方式错误'); return $this->fail('支付方式错误');
} }
@ -296,8 +256,8 @@ class StoreOrderController extends BaseAdminController
if (empty($count)) { if (empty($count)) {
return $this->fail('无该核销码请检查'); return $this->fail('无该核销码请检查');
} }
$params['store_id']=$this->adminInfo['store_id']; $params['store_id'] = $this->adminInfo['store_id'];
$params['staff_id']=$this->adminId; $params['staff_id'] = $this->adminId;
$res = OrderLogic::writeOff($params); $res = OrderLogic::writeOff($params);
if ($res) { if ($res) {
return $this->success('核销成功'); return $this->success('核销成功');
@ -328,17 +288,16 @@ class StoreOrderController extends BaseAdminController
$params['page_no'] = 1; $params['page_no'] = 1;
$params['page_size'] = 15; $params['page_size'] = 15;
} }
$params['store_id'] =$this->request->adminInfo['store_id']; $params['store_id'] = $this->request->adminInfo['store_id'];
$result = $orderLogic->writeList($params); $result = $orderLogic->writeList($params);
$data = [ $data = [
'lists' => $result, 'lists' => $result,
'count' => count($result), 'count' => count($result),
'page_no' => $params['page_no'], 'page_no' => $params['page_no'],
'page_size' =>$params['page_size'], 'page_size' => $params['page_size'],
]; ];
return $this->success('ok',$data); return $this->success('ok', $data);
} }
/** /**
* vip充值 * vip充值
@ -351,16 +310,16 @@ class StoreOrderController extends BaseAdminController
return $this->fail('支付条码不能为空'); return $this->fail('支付条码不能为空');
} }
$params = $this->request->post(); $params = $this->request->post();
$data=[ $data = [
'store_id'=>$this->adminInfo['store_id'], 'store_id' => $this->adminInfo['store_id'],
'uid'=>$params['uid'], 'uid' => $params['uid'],
'staff_id'=>$this->adminId, 'staff_id' => $this->adminId,
'order_id'=>getNewOrderId('CZ'), 'order_id' => getNewOrderId('CZ'),
'price'=>$params['price'], 'price' => $params['price'],
'recharge_type'=>'INDUSTRYMEMBERS', 'recharge_type' => 'INDUSTRYMEMBERS',
]; ];
$order = UserRecharge::create($data); $order = UserRecharge::create($data);
$order['pay_price']=$order['price']; $order['pay_price'] = $order['price'];
switch ($pay_type) { switch ($pay_type) {
case PayEnum::WECHAT_PAY_BARCODE: case PayEnum::WECHAT_PAY_BARCODE:
//微信条码支付 //微信条码支付
@ -371,7 +330,7 @@ class StoreOrderController extends BaseAdminController
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else { } else {
Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']); Redis::send('send-code-pay', ['order_id' => $order['order_id'], 'pay_type' => 'recharge']);
return $this->success('用户支付中'); return $this->success('用户支付中');
} }
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
@ -384,7 +343,7 @@ class StoreOrderController extends BaseAdminController
if ($result['msg'] !== 'Success') { if ($result['msg'] !== 'Success') {
return $this->success('用户支付中'); return $this->success('用户支付中');
} }
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result,'ali'); PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result, 'ali');
$result['create_time'] = $order['create_time']; $result['create_time'] = $order['create_time'];
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]); return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]);
@ -397,10 +356,10 @@ class StoreOrderController extends BaseAdminController
public function stocking() public function stocking()
{ {
$uid = $this->request->post('uid'); $uid = $this->request->post('uid');
$res = (new StoreOrderLogic())->dealSendSms(['uid'=>$uid],1); $res = (new StoreOrderLogic())->dealSendSms(['uid' => $uid], 1);
if($res){ if ($res) {
return $this->success('发送成功',[],0,1); return $this->success('发送成功', [], 0, 1);
}else{ } else {
return $this->fail('发送失败'); return $this->fail('发送失败');
} }
} }
@ -408,22 +367,23 @@ class StoreOrderController extends BaseAdminController
/** /**
* 订单打印 * 订单打印
*/ */
public function print(){ public function print()
$id=$this->request->get('id'); {
$id = $this->request->get('id');
$find = StoreOrder::where('id', $id)->find(); $find = StoreOrder::where('id', $id)->find();
if ($find) { if ($find) {
$merchant = SystemStore::where('id', $find['store_id'])->field('name,phone')->find(); $merchant = SystemStore::where('id', $find['store_id'])->field('name,phone')->find();
$mer_user_info = SystemStoreStaff::where('store_id', $find['store_id'])->where('is_admin',1)->field('staff_name,phone')->find(); $mer_user_info = SystemStoreStaff::where('store_id', $find['store_id'])->where('is_admin', 1)->field('staff_name,phone')->find();
$user = User::where('id', $find['uid'])->field('nickname,mobile')->find(); $user = User::where('id', $find['uid'])->field('nickname,mobile')->find();
$find['system_store_name'] = $merchant['name']; $find['system_store_name'] = $merchant['name'];
$find['pay_type_name'] = PayEnum::getPaySceneDesc($find['pay_type']); $find['pay_type_name'] = PayEnum::getPaySceneDesc($find['pay_type']);
$find['system_store_phone'] = $merchant['phone']; $find['system_store_phone'] = $merchant['phone'];
$find['staff_name'] = $mer_user_info['staff_name']; $find['staff_name'] = $mer_user_info['staff_name'];
$find['staff_phone'] = $mer_user_info['phone']; $find['staff_phone'] = $mer_user_info['phone'];
$find['nickname'] = $user['nickname']??''; $find['nickname'] = $user['nickname'] ?? '';
$find['user_mobile'] = $user['mobile']??''; $find['user_mobile'] = $user['mobile'] ?? '';
$find['info'] = StoreOrderCartInfo::where('oid', $find['id'])->field('store_id,product_id,cart_num,cart_info')->select()->each(function ($item) { $find['info'] = StoreOrderCartInfo::where('oid', $find['id'])->field('store_id,product_id,cart_num,cart_info')->select()->each(function ($item) {
$goods = StoreBranchProduct::where(['store_id'=>$item['store_id'],'product_id'=>$item['product_id']])->field('store_name,unit')->find(); $goods = StoreBranchProduct::where(['store_id' => $item['store_id'], 'product_id' => $item['product_id']])->field('store_name,unit')->find();
$item['unit_name'] = StoreProductUnit::where('id', $goods['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $goods['unit'])->value('name');
$item['store_name'] = $goods['store_name']; $item['store_name'] = $goods['store_name'];
$item['total_price'] = $item['cart_info']['total_price']; $item['total_price'] = $item['cart_info']['total_price'];
@ -432,7 +392,5 @@ class StoreOrderController extends BaseAdminController
}); });
} }
return $this->success('获取成功', $find?->toArray()); return $this->success('获取成功', $find?->toArray());
} }
} }