multi-store/app/api/controller/store/StoreController.php

169 lines
5.8 KiB
PHP
Raw Normal View History

2024-06-01 14:56:45 +08:00
<?php
namespace app\api\controller\store;
2024-06-17 10:02:16 +08:00
use app\admin\logic\user\UserLogic as UserUserLogic;
2024-06-01 14:56:45 +08:00
use app\api\lists\store\SystemStoreLists;
use app\api\controller\BaseApiController;
2024-06-22 17:04:28 +08:00
use app\api\lists\user_create_log\UserCreateLogLists;
2024-06-13 10:27:56 +08:00
use app\api\logic\store\StoreLogic;
2024-06-17 10:02:16 +08:00
use app\api\logic\user\UserLogic;
use app\api\validate\UserValidate;
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
use app\common\logic\PayNotifyLogic;
use app\common\model\Config;
2024-06-17 10:02:16 +08:00
use app\common\model\user\User;
use app\common\model\user_create_log\UserCreateLog;
2024-06-17 10:02:16 +08:00
use app\common\model\user_recharge\UserRecharge;
2024-06-25 10:39:37 +08:00
use support\Cache;
2024-06-17 10:02:16 +08:00
use Webman\RedisQueue\Redis;
2024-06-01 14:56:45 +08:00
class StoreController extends BaseApiController
{
2024-06-13 10:27:56 +08:00
public $notNeedLogin = ['detail'];
2024-06-01 14:56:45 +08:00
public function lists()
{
return $this->dataLists(new SystemStoreLists());
}
2024-06-22 17:04:28 +08:00
/**
* 创建用户记录列表
*/
public function create_lists()
{
return $this->dataLists(new UserCreateLogLists());
}
2024-06-01 14:56:45 +08:00
/**
* 门店信息
*/
2024-06-13 10:27:56 +08:00
public function detail()
{
$store_id = (int)$this->request->get('store_id');
$phone = (int)$this->request->get('phone');
$where = [];
if($phone){
$where['phone'] = $phone;
}
if($store_id){
$where['id'] = $store_id;
}
2024-06-13 10:27:56 +08:00
$info = StoreLogic::search($where);
if ($info) {
2024-06-25 09:46:16 +08:00
return $this->success('ok',$info);
2024-06-13 10:27:56 +08:00
} else {
return $this->fail('店铺不存在');
}
}
2024-06-17 10:02:16 +08:00
/**
* 门店会员充值
*/
public function recharge()
{
$params = (new UserValidate())->post()->goCheck('rechargeStoreMoney');
$auth_code = $this->request->post('auth_code'); //微信支付条码
2024-06-22 16:21:46 +08:00
$recharge_type = $this->request->post('recharge_type',''); //微信支付条码
2024-06-25 15:05:58 +08:00
$code = $this->request->post('code','');//验证码
$phone = $params['mobile'];
if($code && $phone){
$remark = $phone.'_reporting';
$codeCache = Cache::get($remark);
if(empty($codeCache)){
return $this->fail('验证码不存在');
}
if ($codeCache != $code) {
return $this->fail('验证码错误');
}
}
if($params['price']>10000){
return $this->fail('充值金额不能大于10000');
}
$find=User::where('account|mobile',$params['mobile'])->find();
2024-06-17 10:02:16 +08:00
if(!$find){
2024-06-22 17:04:28 +08:00
$params['create_uid']=$this->userId;
2024-06-17 10:02:16 +08:00
$find=UserUserLogic::StoreAdd($params);
}else{
$find['real_name']=$params['real_name'];
$find['label_id']=$params['label_id']??0;
$find->save();
2024-06-17 10:02:16 +08:00
}
2024-06-26 18:07:37 +08:00
if($find === false){
return $this->fail(UserUserLogic::getError());
}
2024-06-22 16:21:46 +08:00
if($recharge_type!='INDUSTRYMEMBERS'){
return $this->success('添加用户成功');
}
2024-06-17 10:02:16 +08:00
$data=[
'store_id'=>$params['store_id'],
'uid'=>$find['id'],
'other_uid'=>$this->userId,
2024-06-17 10:02:16 +08:00
'staff_id'=>0,
'order_id'=>getNewOrderId('CZ'),
'price'=>$params['price']??1000,
'recharge_type'=>'INDUSTRYMEMBERS',
'user_ship'=>$params['user_ship']??0,
2024-06-17 10:02:16 +08:00
];
$order = UserRecharge::create($data);
2024-06-13 10:27:56 +08:00
2024-06-17 10:02:16 +08:00
$order['pay_price']=$order['price'];
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
2024-06-17 10:02:16 +08:00
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else {
Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']);
return $this->success('用户支付中');
}
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
}
/**
* 重新充值会员
*/
public function again_recharge()
{
$auth_code = $this->request->post('auth_code'); //微信支付条码
$id = $this->request->post('id',0); //id
$order = UserRecharge::where('id', $id)->where('paid',0)->find();
if(!$order){
return $this->fail('订单不存在');
}
2024-06-24 17:21:32 +08:00
$order_id=getNewOrderId('CZ');
UserRecharge::where('id', $id)->update(['order_id'=>$order_id]);
$order['order_id']=$order_id;
$order['pay_price']=$order['price'];
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError());
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else {
Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']);
return $this->success('用户支付中');
}
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
}
/**
* 门店会员充值数量
*/
public function recharge_count()
{
$store_id = $this->request->get('store_id',0);
$count=0;
$createLog=0;
if($store_id){
$count= UserRecharge::where(['store_id'=>$store_id,'recharge_type'=>'INDUSTRYMEMBERS','paid'=>1])->count();
$createLog= UserCreateLog::where(['store_id'=>$store_id])->count();
}
return $this->success('ok',['count'=>$count,'create_log'=>$createLog]);
}
2024-06-04 16:51:26 +08:00
}