| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace app\api\controller\user;
- use app\models\store\StoreBargainUser;
- use app\models\store\StoreOrder;
- use app\models\store\StorePink;
- use app\models\system\SystemUserLevel;
- use app\models\system\SystemUserTask;
- use app\models\user\UserLevel;
- use app\models\user\UserLevelOrder;
- use app\Request;
- use crmeb\repositories\OrderRepository;
- use crmeb\services\UtilService;
- /**
- * 会员等级类
- * Class UserLevelController
- * @package app\api\controller\user
- */
- class UserLevelController
- {
- /**
- * 检测用户是否可以成为会员
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function detection(Request $request)
- {
- UserLevel::beginTrans();
- $res = UserLevel::setLevelComplete($request->uid());
- UserLevel::checkTrans($res);
- return app('json')->successful($res);
- }
- /**
- * 会员等级列表
- * @param Request $request
- * @return mixed
- */
- public function grade(Request $request)
- {
- return app('json')->successful(SystemUserLevel::getLevelList($request->uid()));
- }
- /**
- * 获取等级任务
- * @param Request $request
- * @param $id
- * @return mixed
- */
- public function task(Request $request, $id)
- {
- return app('json')->successful(SystemUserTask::getTashList($id, $request->uid()));
- }
- /**
- * 等级购买订单创建
- * @param Request $request
- * @param $key
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function create(Request $request, $level)
- {
- if (!$level) return app('json')->fail('参数错误!');
- $uid = $request->uid();
- // if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
- // return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
- list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
- 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
- ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
- ], $request, true);
- $payType = strtolower($payType);
- $isChannel = 1;
- if ($from == 'weixin')
- $isChannel = 0;
- elseif ($from == 'weixinh5')
- $isChannel = 2;
- $order = UserLevelOrder::CreateOrder($request->uid(), $addressId, $payType);
- if ($order === false) return app('json')->fail(UserLevelOrder::getErrorInfo('订单生成失败'));
- $orderId = $order['order_id'];
- // $info = compact('orderId', 'key');
- $info = $orderId;
- if ($orderId) {
- event('OrderCreated', [$order]); //订单创建成功事件
- // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
- switch ($payType) {
- case "weixin":
- $orderInfo = UserLevelOrder::where('order_id', $orderId)->find();
- if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
- $orderInfo = $orderInfo->toArray();
- if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
- //支付金额为0
- if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
- //创建订单jspay支付
- $payPriceStatus = UserLevelOrder::jsPayPrice($orderId, $uid, $formId);
- if ($payPriceStatus)//0元支付成功
- return app('json')->status('success', '微信支付成功', $info);
- else
- return app('json')->status('pay_error', UserLevelOrder::getErrorInfo());
- } else {
- try {
- if ($from == 'routine') {
- $jsConfig = OrderRepository::jsPay($orderId); //创建订单jspay
- } else if ($from == 'weixinh5') {
- $jsConfig = OrderRepository::h5Pay($orderId);
- } else {
- $jsConfig = OrderRepository::wxPay($orderId);
- }
- } catch (\Exception $e) {
- return app('json')->status('pay_error', $e->getMessage(), $info);
- }
- $info['jsConfig'] = $jsConfig;
- if ($from == 'weixinh5') {
- return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
- } else {
- return app('json')->status('wechat_pay', '订单创建成功', $info);
- }
- }
- break;
- case 'yue':
- if (UserLevelOrder::yuePay($orderId, $request->uid(), $formId))
- return app('json')->status('success', '余额支付成功', $info);
- else {
- $errorinfo = UserLevelOrder::getErrorInfo();
- if (is_array($errorinfo))
- return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
- else
- return app('json')->status('pay_error', $errorinfo);
- }
- break;
- case 'offline':
- return app('json')->status('success', '订单创建成功', $info);
- break;
- }
- } else return app('json')->fail(UserLevelOrder::getErrorInfo('订单生成失败!'));
- }
- }
|