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

77 lines
2.5 KiB
PHP

<?php
namespace app\api\controller\store;
use app\admin\logic\user\UserLogic as UserUserLogic;
use app\api\lists\store\SystemStoreLists;
use app\api\controller\BaseApiController;
use app\api\logic\store\StoreLogic;
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\user\User;
use app\common\model\user_recharge\UserRecharge;
use Webman\RedisQueue\Redis;
class StoreController extends BaseApiController
{
public $notNeedLogin = ['detail'];
public function lists()
{
return $this->dataLists(new SystemStoreLists());
}
public function detail()
{
$store_id = (int)$this->request->get('store_id');
$where = [
'id' => $store_id
];
$info = StoreLogic::search($where);
if ($info) {
return $this->data($info);
} else {
return $this->fail('店铺不存在');
}
}
/**
* 门店会员充值
*/
public function recharge()
{
$params = (new UserValidate())->post()->goCheck('rechargeStoreMoney');
$auth_code = $this->request->post('auth_code'); //微信支付条码
$params['uid'] = $this->userId;
$params['channel_type'] = $this->userInfo['terminal'];
$find=User::where('mobile',$params['mobile'])->find();
if(!$find){
$find=UserUserLogic::StoreAdd($params);
}
$data=[
'store_id'=>$params['store_id'],
'uid'=>$find['uid'],
'staff_id'=>0,
'order_id'=>getNewOrderId('CZ'),
'price'=>1000,
];
$order = UserRecharge::create($data);
$order['pay_price']=$order['price'];
$result = PaymentLogic::codepay($auth_code, $order,'条码支付');
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']]);
}
}