| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace app\controller\api;
- use app\extra\basic\Base;
- use app\extra\dyLife\Token;
- use app\extra\dyMini\Relation;
- use app\extra\tools\CodeExtend;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasGoods;
- use app\model\saas\SaasGoodsSku;
- use app\model\saas\SaasOrder;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\RequestMapping;
- use support\Request;
- use support\Response;
- /**
- * 解决方案回传
- */
- #[Controller("/solution")]
- class Solution extends Base
- {
- #[RequestMapping(path: "notify")]
- public function getSolutionData(Request $request): Response
- {
- try {
- $data = $request->all();
- echo getDateFull()."===扩展回调\n";
- print_r($data);
- if (isset($data['operate_type'])) {
- if ($data['status'] == "PASS") { // 创建商品回调
- $goods = (new SaasGoods)->where("goods_id",$data['product_id'])->findOrEmpty();
- if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
- $goods->status = 1;
- $goods->save();
- }
- }
- if (isset($data['type']))
- {
- $msgData = json_decode($data['msg'],true);
- switch ($data['type'])
- {
- case "pre_create_refund": // 退款回调
- $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
- if ($order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
- if ($order['status'] <> 1) return json(['err_no' => 0,"err_tips" => "success"]);
- $order->status = 4; // 退款中
- $order->refund_msg = json_encode($msgData['refund_reason']);
- $order->refund_apply = getDateFull();
- $order->save();
- return json(['err_no' => 0,"err_tips" => "success","data" => [
- "out_refund_no" => "R".$order['out_order_no'],
- "order_entry_schema" => [
- "path" => "pages/order/detail",
- "params" => json_encode([
- "order" => $order['out_order_no']
- ])
- ],
- "notify_url" => "https://tran.jsshuita.cn/notify/refund"
- ]]);
- break;
- case "pre_create_order": // 预下单
- echo getDateFull()."====预下单\n";
- print_r($msgData);
- if (!isset($msgData['item_order_info_list'][0]['goods_id'])) return json(['err_no' => 0,"err_tips" => "success"]);
- if (empty($msgData['cp_extra'])) return json(['err_no' => 0,"err_tips" => "success"]);
- $cp_extra = json_decode($msgData['cp_extra'],true);
- $skuGoods = [];
- if ($cp_extra['product_id'] <> $cp_extra['sku_id']) { // 多规格下单
- $skuGoods = (new SaasGoodsSku)->where(['product_id' => $cp_extra['product_id'],'sku_id' => $cp_extra['sku_id']])->findOrEmpty();
- }
- $goods = (new SaasGoods)->where("goods_id",$msgData['item_order_info_list'][0]['goods_id'])->findOrEmpty();
- if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
- $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
- if (!$order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
- $orderSn = "AL".CodeExtend::uniqidDate(18).rand(100,999);
- $goodsImg = is_string($goods['image_list'])?json_decode($goods['image_list'],true):$goods['image_list'];
- $order->insertGetId([
- "out_order_no" => $orderSn,
- "order_sn" => $msgData['order_id'],
- "openid" => $msgData['open_id'],
- "goods_id" => $goods['id'],
- "life_goods_id" => $goods['goods_id'],
- "product_id" => $goods['product_id'],
- "sku_id" => $cp_extra['sku_id'],
- "number" => $msgData['goods'][0]['quantity']??1,
- "price" => $msgData['item_order_info_list'][0]['price']?:$goods['price'],
- "custom_price" => empty($skuGoods)?$goods['custom_price']:$skuGoods['custom_price'], // 补差价金额
- "line_price" => $goods['line_price']*100,
- "poi_id" => $goods['poi_id'],
- "img" => $goodsImg[0]['url'],
- "sku_name" => $cp_extra['name'],
- "mobile" => $msgData['phone_num']??'',
- "pay_money" => $msgData['total_amount']??0,
- ]);
- return json(['err_no' => 0,"err_tips" => "success","data" => [
- "order_entry_schema" => [
- "path" => "pages/order/detail",
- "params" => json_encode([
- "order" => $orderSn
- ])
- ],
- "out_order_no" => $orderSn,
- "pay_expire_seconds" => 1800,
- "pay_notify_url" => "https://tran.jsshuita.cn/notify/douyin"
- ]]);
- break;
- default:
- break;
- }
- }
- return json(['err_no' => 0,"err_tips" => "success"]);
- } catch (\Throwable $throwable) {
- echo $throwable->getMessage()."\n";
- echo $throwable->getLine()."\n";
- echo $throwable->getFile()."\n";
- return error($throwable->getMessage());
- }
- }
- #[GetMapping("token")]
- public function setTestToken(Request $request): Response
- {
- try {
- $param = $this->_valid([
- "code.require" => ""
- ]);
- if (!is_array($param)) return error($param);
- $data = (new Token)->config($this->getDyConfig())->token()->getAccessTokenUser($param['code']);
- return success("ok",$data);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- #[GetMapping("test")]
- public function setTest()
- {
- try {
- $data = (new Relation)->config($this->getDyConfig())->token()->createOrderFirst(['1865253598118939']);
- return success("ok",$data);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|