浏览代码

完成支付宝支付及回调

xiaohai 3 周前
父节点
当前提交
4232d94c6a

+ 3
- 3
app/admin/logic/shop/GoodsRenewLogic.php 查看文件

@@ -3,8 +3,8 @@
3 3
  * @Author: ZMH
4 4
  * @Email: zmhwork@qq.com
5 5
  * @Date: 2025-03-13 11:47:30
6
- * @LastEditTime: 2025-03-13 17:41:19
7
- * @LastEditors: ZMH
6
+ * @LastEditTime: 2025-03-14 18:02:56
7
+ * @LastEditors: xiaohai zmhwork@qq.com
8 8
  * @FilePath: \opkpm\app\admin\logic\shop\GoodsRenewLogic.php
9 9
  * 
10 10
  * @Description: 续费逻辑处理
@@ -28,7 +28,7 @@ class GoodsRenewLogic extends Logic
28 28
             ['del', '=', 0]
29 29
         ];
30 30
 
31
-        if (!empty($get['name']) and $get['name'])
31
+        if (!empty($get['name']) && $get['name'])
32 32
             $where[] = ['name', 'like', '%' . $get['name'] . '%'];
33 33
 
34 34
         $model = new ShopGoodsRenew();

+ 15
- 0
app/common/model/shop/OrderRenew.php 查看文件

@@ -0,0 +1,15 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-14 16:47:53
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-14 17:19:06
7
+ * @FilePath: \opkpm\app\common\model\shop\OrderRenew.php
8
+ * @Description: 续费订单
9
+ */
10
+
11
+namespace app\common\model\shop;
12
+
13
+use app\common\basics\Models;
14
+
15
+class OrderRenew extends Models {}

+ 15
- 0
app/common/model/shop/ShopHkLog.php 查看文件

@@ -0,0 +1,15 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-17 15:56:14
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-17 15:56:26
7
+ * @FilePath: \opkpm\app\common\model\shop\ShopHkLog.php
8
+ * @Description: 获客记录
9
+ */
10
+
11
+namespace app\common\model\shop;
12
+
13
+use app\common\basics\Models;
14
+
15
+class ShopHkLog extends Models {}

+ 108
- 0
app/shop/controller/order/OrderRenew.php 查看文件

@@ -0,0 +1,108 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-14 17:27:51
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-17 16:24:30
7
+ * @FilePath: \opkpm\app\shop\controller\order\OrderRenew.php
8
+ * @Description: 续费订单
9
+ */
10
+
11
+namespace app\shop\controller\order;
12
+
13
+use app\common\basics\ShopBase;
14
+use app\common\server\JsonServer;
15
+use app\shop\logic\order\OrderRenewLogic;
16
+use Nette\Utils\Json;
17
+
18
+class OrderRenew extends ShopBase
19
+{
20
+    public function lists()
21
+    {
22
+        if ($this->request->isAjax()) {
23
+            $get = $this->request->get();
24
+            $get['shop_id'] = $this->shop_id;
25
+            return JsonServer::success('', OrderRenewLogic::lists($get));
26
+        }
27
+
28
+        return view('');
29
+    }
30
+
31
+    public function renewLists()
32
+    {
33
+        if ($this->request->isAjax()) {
34
+            $get = $this->request->get();
35
+            $get['shop_id'] = $this->shop_id;
36
+            return JsonServer::success('', OrderRenewLogic::renewLists($get));
37
+        }
38
+
39
+        return view('');
40
+    }
41
+
42
+    public function buy()
43
+    {
44
+        $get = $this->request->get();
45
+        $get['shop_id'] = $this->shop_id;
46
+        $id = $get['id'] ?? 0;
47
+        $data = OrderRenewLogic::buy($id);
48
+
49
+        return view('', ['detail' => $data]);
50
+    }
51
+
52
+    public function add()
53
+    {
54
+        if ($this->request->isPost()) {
55
+            $post = $this->request->post();
56
+            $post['shop_id'] = $this->shop_id;
57
+            $data = OrderRenewLogic::add($post);
58
+            if (!$data) {
59
+                return JsonServer::error(OrderRenewLogic::getError());
60
+            }
61
+
62
+            return JsonServer::success('', $data);
63
+        }
64
+
65
+        return JsonServer::error('请求方式错误');
66
+    }
67
+
68
+    public function cancel()
69
+    {
70
+        if ($this->request->isPost()) {
71
+            $post = $this->request->post();
72
+            $post['shop_id'] = $this->shop_id;
73
+            $data = OrderRenewLogic::cancel($post);
74
+            if (!$data) {
75
+                return JsonServer::error(OrderRenewLogic::getError());
76
+            }
77
+
78
+            return JsonServer::success('操作成功');
79
+        }
80
+
81
+        return JsonServer::error('请求方式错误');
82
+    }
83
+
84
+    public function payPage()
85
+    {
86
+        $get = $this->request->get();
87
+        $get['shop_id'] = $this->shop_id;
88
+        $data = OrderRenewLogic::payPage($get);
89
+
90
+        return view('', ['detail' => $data]);
91
+    }
92
+
93
+    public function payWay()
94
+    {
95
+        if ($this->request->isPost()) {
96
+            $post = $this->request->post();
97
+            $post['shop_id'] = $this->shop_id;
98
+            $data = OrderRenewLogic::payWay($post);
99
+            if (!$data) {
100
+                return JsonServer::error(OrderRenewLogic::getError());
101
+            }
102
+
103
+            return JsonServer::success('', ['page' => $data]);
104
+        }
105
+
106
+        return JsonServer::error('请求方式错误');
107
+    }
108
+}

+ 34
- 0
app/shop/controller/order/Pay.php 查看文件

@@ -0,0 +1,34 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-17 14:27:51
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-17 18:02:17
7
+ * @FilePath: \opkpm\app\shop\controller\order\Pay.php
8
+ * @Description: 支付回调
9
+ */
10
+
11
+namespace app\shop\controller\order;
12
+
13
+use app\common\basics\ShopBase;
14
+use app\common\server\JsonServer;
15
+use app\shop\logic\order\OrderRenewLogic;
16
+use think\facade\Log;
17
+
18
+class Pay extends ShopBase
19
+{
20
+    public $like_not_need_login = ['notifyMnp', 'notifyOa', 'notifyApp', 'aliNotify'];
21
+
22
+    public function aliNotify()
23
+    {
24
+        $post = $this->request->post();
25
+        Log::info('aliNotify 支付宝回调:' . json_encode($post));
26
+        $data = OrderRenewLogic::aliNotify($post);
27
+        if (!$data) {
28
+            Log::error('aliNotify 支付宝回调错误:' . OrderRenewLogic::getError());
29
+            return JsonServer::error(OrderRenewLogic::getError());
30
+        }
31
+
32
+        return 'success';
33
+    }
34
+}

+ 335
- 0
app/shop/logic/order/OrderRenewLogic.php 查看文件

@@ -0,0 +1,335 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-14 17:38:50
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-17 18:43:05
7
+ * @FilePath: \opkpm\app\shop\logic\order\OrderRenewLogic.php
8
+ * @Description: 续费订单逻辑处理
9
+ */
10
+
11
+namespace app\shop\logic\order;
12
+
13
+use app\common\model\shop\OrderRenew;
14
+use app\common\model\shop\ShopGoodsRenew;
15
+
16
+use app\common\basics\Logic;
17
+use app\common\enum\OrderEnum;
18
+use app\common\model\shop\Shop;
19
+use app\common\model\shop\ShopHkLog;
20
+use app\common\server\AliPayServer;
21
+use app\common\server\YansongdaAliPayServer;
22
+use app\shop\validate\order\OrderRenewValidate;
23
+use think\facade\Db;
24
+use think\facade\Log;
25
+use Yansongda\Pay\Pay;
26
+
27
+class OrderRenewLogic extends Logic
28
+{
29
+    public static function lists($get)
30
+    {
31
+        $page = $get['page'] ?? 1;
32
+        $limit = $get['limit'] ?? 10;
33
+
34
+        $where[] = ['del', '=', 0];
35
+        $where[] = ['shop_id', '=', $get['shop_id']];
36
+
37
+        $count = OrderRenew::where($where)->count();
38
+        $lists = OrderRenew::where($where)
39
+            ->page($page, $limit)
40
+            ->order('id', 'desc')
41
+            ->select()->toArray();
42
+        foreach ($lists as $key => $value) {
43
+            $lists[$key]['type_str'] = $value['renew_type_id'] == 0 ? '包月' : '按量付费';
44
+            $lists[$key]['order_status_str'] = OrderEnum::getOrderStatus($value['order_status']);
45
+            $lists[$key]['pay_status_str'] = OrderEnum::getPayStatus($value['pay_status']);
46
+            $lists[$key]['pay_way_str'] = $value['pay_way'] == 1 ? '微信' : '支付宝';
47
+            $lists[$key]['pay_time_str'] = $value['pay_time'] ? date('Y-m-d H:i:s', $value['pay_time']) : '';
48
+        }
49
+
50
+        return ['count' => $count, 'lists' => $lists];
51
+    }
52
+
53
+    public static function renewLists($get)
54
+    {
55
+        $page = $get['page'] ?? 1;
56
+        $limit = $get['limit'] ?? 10;
57
+
58
+        $where = [
59
+            ['del', '=', 0],
60
+            ['status', '=', 1]
61
+        ];
62
+
63
+        if (!empty($get['name']) && $get['name']) {
64
+            $where[] = ['name', 'like', '%' . $get['name'] . '%'];
65
+        }
66
+        // var_dump($get, $where);        
67
+
68
+        $count = ShopGoodsRenew::where($where)->count();
69
+        $lists = ShopGoodsRenew::where($where)
70
+            ->page($page, $limit)
71
+            ->order('id', 'desc')
72
+            ->select()->toArray();
73
+        foreach ($lists as $key => $value) {
74
+            $lists[$key]['type_str'] = $value['type_id'] == 0 ? '包月' : '按量付费';
75
+            $lists[$key]['status_str'] = $value['status'] == 0 ? '禁用' : '启用';
76
+        }
77
+
78
+        return ['count' => $count, 'lists' => $lists];
79
+    }
80
+
81
+    public static function buy($id)
82
+    {
83
+        $where = [
84
+            ['del', '=', 0],
85
+            ['status', '=', 1],
86
+            ['id', '=', $id]
87
+        ];
88
+        $info = ShopGoodsRenew::where($where)->find();
89
+        if (!$info) {
90
+            static::$error = '数据不存在';
91
+            return false;
92
+        }
93
+
94
+        return $info->toArray();
95
+    }
96
+
97
+    
98
+    public static function cancel($post)
99
+    {
100
+        try {
101
+            validate(OrderRenewValidate::class)->scene('cancel')->check($post);
102
+        } catch (\Exception $e) {
103
+            static::$error = $e->getMessage();
104
+            return false;
105
+        }
106
+
107
+        $where = [
108
+            ['del', '=', 0],
109
+            ['id', '=', $post['id']],
110
+            ['shop_id', '=', $post['shop_id']],
111
+        ];
112
+
113
+        $info = OrderRenew::where($where)->find();
114
+        if (!$info) {
115
+            self::$error = '数据不存在';
116
+            return false;
117
+        }
118
+
119
+        if ($info->order_status > 0) {
120
+            self::$error = '订单状态不可取消';
121
+            return false;
122
+        }
123
+
124
+        $info->order_status = 4;
125
+        $info->save();
126
+
127
+        return true;
128
+    }
129
+
130
+    public static function add($post)
131
+    {
132
+        try {
133
+            validate(OrderRenewValidate::class)->scene('add')->check($post);
134
+        } catch (\Exception $e) {
135
+            static::$error = $e->getMessage();
136
+            return false;
137
+        }
138
+
139
+        $model = new OrderRenew();
140
+        $name = $model->getName();
141
+        $post['order_sn'] = createSn($name, 'order_sn');
142
+        $post['renew_name'] = $post['name'];
143
+        $post['renew_image'] = $post['image'];
144
+        $post['renew_desc'] = $post['desc'];
145
+        $post['renew_type_id'] = $post['type_id'];
146
+        $post['renew_price'] = $post['price'];
147
+        $post['renew_op_count'] = $post['op_count'];
148
+
149
+        $post['total_amount'] = $post['renew_price'] * $post['renew_num'];
150
+        $post['total_num'] = $post['renew_num'];
151
+        $post['order_amount'] = $post['total_amount'];
152
+
153
+        $info = $model->create($post);
154
+
155
+        return $info->toArray();
156
+    }
157
+
158
+    public static function payPage($get)
159
+    {
160
+        $where = [
161
+            ['del', '=', 0],
162
+            ['id', '=', $get['id']],
163
+            ['shop_id', '=', $get['shop_id']],
164
+        ];
165
+
166
+        $info = OrderRenew::where($where)->find();
167
+        if (!$info) {
168
+            static::$error = '数据不存在';
169
+            return false;
170
+        }
171
+
172
+        return $info->toArray();
173
+    }
174
+
175
+    private static function aliPay($info, $time_expire)
176
+    {
177
+        // 支付宝PC端支付
178
+        $domain = request()->domain();
179
+
180
+        $return_url = (string) url('shop/order.OrderRenew/lists', [], false, true);
181
+        $notify_url = (string) url('shop/order.Pay/aliNotify', [], false, true);
182
+
183
+        $ali_data = [
184
+            'out_trade_no'      => $info['order_sn'],
185
+            'total_amount'      => $info['order_amount'],
186
+            'subject'           => '订单:' . $info['order_sn'],
187
+            // 'return_url'        => $domain . '/shop/order.OrderRenew/lists',
188
+            'return_url'        => $return_url,
189
+            'time_expire'   => date('Y-m-d H:i:s', $time_expire),
190
+        ];
191
+
192
+        $aliPayConf = YansongdaAliPayServer::config();
193
+        $aliPayConf['notify_url'] = $notify_url;
194
+
195
+        $aliPay = Pay::alipay($aliPayConf);
196
+
197
+        // $ali_data['notify_url'] = $domain . '/shop/order.Pay/aliNotify';
198
+        $ali_data['notify_url'] = $notify_url;
199
+        return $aliPay->web($ali_data)->getContent();
200
+    }
201
+
202
+    public static function payWay($post)
203
+    {
204
+        try {
205
+            validate(OrderRenewValidate::class)->scene('pay_way')->check($post);
206
+        } catch (\Exception $e) {
207
+            static::$error = $e->getMessage();
208
+            return false;
209
+        }
210
+
211
+        $where = [
212
+            ['del', '=', 0],
213
+            ['id', '=', $post['id']],
214
+            ['shop_id', '=', $post['shop_id']],
215
+        ];
216
+
217
+        $info = OrderRenew::where($where)->find();
218
+        if (!$info) {
219
+            static::$error = '数据不存在';
220
+            return false;
221
+        }
222
+
223
+        if ($info['order_status'] > 0) {
224
+            static::$error = '订单不处于可支付状态下';
225
+            return false;
226
+        }
227
+
228
+        $time_expire = time() + 3600 * 2;
229
+
230
+        $info->pay_way = $post['pay_way'];
231
+        $info->time_expire = $time_expire - 600;
232
+        $info->save();
233
+
234
+        if ($post['pay_way'] == 2) {
235
+            return self::aliPay($info, $time_expire);
236
+        }
237
+
238
+        self::$error = '暂不支持该支付方式';
239
+        return false;
240
+    }
241
+
242
+    private static function changeHkCount($info, $time)
243
+    {
244
+        // 添加用户套餐时间或者数量
245
+        // 操作数量
246
+        $op_count = $info['renew_op_count'] * $info['total_num'];
247
+        $shop = Shop::find($info['shop_id']);
248
+        // 包月
249
+        if ($info['renew_type_id'] == 0) {
250
+            $old_expire_time = $shop['expire_time'];
251
+            if ($old_expire_time < $time) {
252
+                $old_expire_time = $time;
253
+            }
254
+
255
+            $di = \DateInterval::createFromDateString(strval($op_count) . ' months');
256
+            $dt = date_create_from_format('Y-m-d H:i:s', date('Y-m-d H:i:s', $old_expire_time))->add($di);
257
+            $dt_str = $dt->format('Y-m-d 00:00:00');
258
+            $shop->expire_time = strtotime($dt_str);
259
+        } else {
260
+            // 按量付费
261
+            // 添加数量记录
262
+            $old_hksy_count = $shop->hksy_count;
263
+            $hk = new ShopHkLog();
264
+            $hk->shop_id = $shop['id'];
265
+            $hk->source_id = $info->id;
266
+            $hk->change_count = $op_count;
267
+            $hk->left_count = $op_count + $old_hksy_count;
268
+            $hk->remark = '[' . $info->renew_name . '],订单号:' . $info->order_sn;
269
+            $hk->save();
270
+
271
+            $shop->hksy_count += $op_count;
272
+        }
273
+
274
+        $shop->save();
275
+
276
+        return true;
277
+    }
278
+
279
+    private static function aliPaySucc($order_sn, $result)
280
+    {
281
+        $time = time();
282
+        Db::startTrans();
283
+
284
+        try {
285
+            $where = [
286
+                ['del', '=', 0],
287
+                ['order_sn', '=', $order_sn],
288
+            ];
289
+
290
+            $info = OrderRenew::where($where)->find();
291
+            if (empty($info)) {
292
+                static::$error = '数据不存在';
293
+                return false;
294
+            }
295
+
296
+            $info->order_status = 3;
297
+            $info->pay_status = 1;
298
+            $info->pay_time = $time;
299
+            $info->notify_content = $result->toJson();
300
+            $info->buyer_id = $result->buyer_open_id;
301
+            $info->trade_no = $result->trade_no;
302
+            $info->save();
303
+
304
+            self::changeHkCount($info, $time);
305
+
306
+            Db::commit();
307
+        } catch (\Exception $e) {
308
+            Db::rollback();
309
+            Log::error('aliPaySucc 支付宝回调错误:' . $e->getMessage());
310
+            static::$error = $e->getMessage();
311
+            return false;
312
+        }
313
+
314
+        return true;
315
+    }
316
+
317
+    public static function aliNotify($post)
318
+    {
319
+        try {
320
+            $aliPayConf = YansongdaAliPayServer::config();
321
+            $aliPay = Pay::alipay($aliPayConf);
322
+            $result = $aliPay->verify($post);
323
+        } catch (\Exception $e) {
324
+            static::$error = $e->getMessage();
325
+            return false;
326
+        }
327
+
328
+        // 支付成功
329
+        if ($result->trade_status === 'TRADE_SUCCESS') {
330
+            self::aliPaySucc($result->out_trade_no, $result);
331
+        }
332
+
333
+        return true;
334
+    }
335
+}

+ 54
- 0
app/shop/validate/order/OrderRenewValidate.php 查看文件

@@ -0,0 +1,54 @@
1
+<?php
2
+/*
3
+ * @Author: xiaohai zmhwork@qq.com
4
+ * @Date: 2025-03-17 10:36:54
5
+ * @LastEditors: xiaohai zmhwork@qq.com
6
+ * @LastEditTime: 2025-03-17 13:42:47
7
+ * @FilePath: \opkpm\app\shop\validate\order\OrderRenewValidate.php
8
+ * @Description: 续费订单验证
9
+ */
10
+
11
+namespace app\shop\validate\order;
12
+
13
+use app\common\basics\Validate;
14
+
15
+use app\common\model\shop\OrderRenew;
16
+use app\common\model\shop\ShopGoodsRenew;
17
+
18
+class OrderRenewValidate extends Validate
19
+{
20
+    protected $rule = [
21
+        'id' => 'require',
22
+        'shop_id|用户' => 'require|number|gt:0',
23
+        'renew_id|套餐' => 'require|number|gt:0|checkTypePay',
24
+        'renew_num|续费数量' => 'require|number|gt:0',
25
+        'pay_way|支付方式' => 'require|number|in:1,2',
26
+    ];
27
+
28
+    protected $message = [
29
+        'id.require' => '缺少ID字段',
30
+    ];
31
+
32
+    protected $scene = [
33
+        'detail' => ['id', 'shop_id'],
34
+        'add' => ['shop_id', 'renew_id', 'renew_num'],
35
+        'cancel' => ['id', 'shop_id'],
36
+        'pay_way' => ['id', 'shop_id', 'pay_way'],
37
+    ];
38
+
39
+    // 查看同类型订单是否有待支付状态
40
+    protected function checkTypePay($value, $rule, $data)
41
+    {
42
+        $renew = ShopGoodsRenew::where('id', $data['renew_id'])->where('status',1)->where("del", 0)->findOrEmpty();
43
+        if ($renew->isEmpty()) {
44
+            return '续费套餐不存在';
45
+        }
46
+        
47
+        $order = OrderRenew::where(['shop_id' => $data['shop_id'], 'renew_id' => $data['renew_id'], 'order_status' => 0])->findOrEmpty();
48
+        if (!$order->isEmpty()) {
49
+            return '已存在' . $renew['name'] . '待支付的订单';
50
+        }
51
+
52
+        return true;
53
+    }
54
+}

+ 97
- 0
app/shop/view/order/order_renew/buy.html 查看文件

@@ -0,0 +1,97 @@
1
+<!--
2
+ * @Author: xiaohai zmhwork@qq.com
3
+ * @Date: 2025-03-14 18:14:19
4
+ * @LastEditors: xiaohai zmhwork@qq.com
5
+ * @LastEditTime: 2025-03-14 18:32:11
6
+ * @FilePath: \opkpm\app\shop\view\order\order_renew\buy.html
7
+ * @Description: 续费套餐购买
8
+-->
9
+{layout name="layout2" /}
10
+
11
+<div class="layui-card layui-form" style="box-shadow:none;">
12
+    <div class="layui-card-body">
13
+        <div class="layui-form-item">
14
+            <label for="name" class="layui-form-label"><span style="color:red;">*</span>续费套餐:</label>
15
+            <div class="layui-input-block">
16
+                <input type="text" name="name" id="name" value="{$detail.name}" lay-verType="tips" lay-verify="required"
17
+                    autocomplete="off" class="layui-input" readonly>
18
+            </div>
19
+        </div>
20
+        <div class="layui-form-item">
21
+            <label class="layui-form-label"><span style="color:red;">*</span>套餐图片:</label>
22
+            <div class="layui-input-block">
23
+                <div class="like-upload-image">
24
+                    {if $detail.image}
25
+                    <div class="upload-image-div">
26
+                        <img src="{$detail.image}" alt="img">
27
+                        <input type="hidden" name="image" value="{$detail.image}">
28
+                        <div class="del-upload-btn">x</div>
29
+                    </div>
30
+                    {/if}
31
+                </div>
32
+            </div>
33
+        </div>
34
+
35
+
36
+        <div class="layui-form-item">
37
+            <label for="name" class="layui-form-label">描述:</label>
38
+            <div class="layui-input-block">
39
+                <input type="text" name="desc" id="desc" autocomplete="off" class="layui-input" value="{$detail.desc}" readonly>
40
+            </div>
41
+        </div>
42
+
43
+        <div class="layui-form-item">
44
+            <label class="layui-form-label">类型</label>
45
+            <div class="layui-input-block">
46
+                <select name="type_id" lay-verify="required" readonly>
47
+                    <option value="0" {neq name="detail.type_id" value="0"}disabled{/neq}>包月</option>
48
+                    <option value="1" {neq name="detail.type_id" value="1"}disabled{/neq}>按量付费</option>
49
+                </select>
50
+            </div>
51
+        </div>
52
+
53
+        <div class="layui-form-item">
54
+            <label for="price" class="layui-form-label"><span style="color:red;">*</span>价格:</label>
55
+            <div class="layui-input-block">
56
+                <input type="number" name="price" id="price" lay-verType="tips" lay-verify="required" autocomplete="off"
57
+                    class="layui-input" value="{$detail.price}" readonly>
58
+            </div>
59
+        </div>
60
+
61
+        <div class="layui-form-item">
62
+            <label for="op_count" class="layui-form-label"><span style="color:red;">*</span>月份数/操作数:</label>
63
+            <div class="layui-input-block">
64
+                <input type="number" name="op_count" id="op_count" lay-verType="tips" lay-verify="required"
65
+                    autocomplete="off" class="layui-input" value="{$detail.op_count}" readonly>
66
+            </div>
67
+        </div>
68
+
69
+
70
+        <div class="layui-form-item">
71
+            <label for="renew_num" class="layui-form-label"><span style="color:red;">*</span>购买数量:</label>
72
+            <div class="layui-input-block">
73
+                <input type="number" name="renew_num" id="renew_num" value="1" autocomplete="off"
74
+                    class="layui-input">
75
+            </div>
76
+        </div>
77
+
78
+        <div class="layui-form-item layui-hide">
79
+            <input type="button" lay-submit lay-filter="addSubmit" id="addSubmit" value="确认">
80
+        </div>
81
+    </div>
82
+</div>
83
+
84
+<script>
85
+    layui.use([], function () {
86
+
87
+        like.delUpload();
88
+        $(document).on("click", ".add-upload-image", function () {
89
+            like.imageUpload({
90
+                limit: 1,
91
+                field: "image",
92
+                that: $(this)
93
+            });
94
+        })
95
+
96
+    })
97
+</script>

+ 120
- 0
app/shop/view/order/order_renew/lists.html 查看文件

@@ -0,0 +1,120 @@
1
+{layout name="layout1" /}
2
+
3
+<div class="wrapper">
4
+    <div class="layui-card">
5
+        <!-- 操作提示 -->
6
+        <div class="layui-card-body">
7
+            <div class="layui-collapse" style="border:1px dashed #c4c4c4">
8
+                <div class="layui-colla-item">
9
+                    <h2 class="layui-colla-title like-layui-colla-title">操作提示</h2>
10
+                    <div class="layui-colla-content layui-show">
11
+                        <p>*续费套餐管理。</p>
12
+                    </div>
13
+                </div>
14
+            </div>
15
+        </div>
16
+
17
+        <!-- 搜索区域 -->
18
+        <div class="layui-card-body layui-form">
19
+            <div class="layui-form-item">
20
+                <div class="layui-inline">
21
+                    <label for="renew_name" class="layui-form-label">续费套餐:</label>
22
+                    <div class="layui-input-inline">
23
+                        <input type="text" id="renew_name" name="renew_name" autocomplete="off" class="layui-input">
24
+                    </div>
25
+                </div>
26
+                <div class="layui-inline">
27
+                    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">搜索</a>
28
+                    <a class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</a>
29
+                </div>
30
+            </div>
31
+        </div>
32
+
33
+        <!-- 主体区域 -->
34
+        <div class="layui-card-body">
35
+            <table id="like-table-lists" lay-filter="like-table-lists"></table>
36
+            <script type="text/html" id="table-image">
37
+                {{#  if(d.image){ }}
38
+                    <img src="{{d.image}}" alt="图标" style="width:28px;height:28px;">
39
+                {{#  } }}
40
+            </script>
41
+            <script type="text/html" id="table-operation">
42
+                {{#  if(d.order_status == 0){ }}
43
+                    <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="pay">点击支付</a>
44
+                    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="cancel">取消订单</a>
45
+                {{#  } }}
46
+            </script>
47
+        </div>
48
+
49
+    </div>
50
+</div>
51
+
52
+<script>
53
+    layui.use(["table", "form"], function () {
54
+        var table = layui.table;
55
+        var form = layui.form;
56
+
57
+
58
+        like.tableLists("#like-table-lists", "{:url()}", [
59
+            { field: "id", width: 80, title: "ID" }
60
+            , { field: "renew_name", width: 260, align: "center", title: "续费套餐" }
61
+            , { field: "order_sn", width: 200, align: "center", title: "订单编号" }
62
+            , { field: "renew_price", width: 100, align: "center", title: "套餐总价" }
63
+            , { field: "total_num", width: 100, align: "center", title: "套餐数量" }
64
+            , { field: "order_status_str", width: 100, align: "center", title: "订单状态" }
65
+            , { field: "pay_status_str", width: 100, align: "center", title: "支付状态" }
66
+            , { field: "pay_way_str", width: 100, align: "center", title: "支付方式" }
67
+            , { field: "pay_time_str", width: 200, align: "center", title: "支付时间" }
68
+            , { title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#table-operation" }
69
+        ]);
70
+
71
+
72
+        var active = {
73
+            pay: function (obj) {
74
+                window.open("{:url('order.OrderRenew/payPage')}?id=" + obj.data.id);
75
+            },
76
+            cancel: function (obj) {
77
+                layer.confirm("确定取消该订单吗:" + obj.data.order_sn, function (index) {
78
+                    like.ajax({
79
+                        url: "{:url('order.OrderRenew/cancel')}",
80
+                        data: { id: obj.data.id },
81
+                        type: "POST",
82
+                        success: function (res) {
83
+                            if (res.code === 1) {
84
+                                layui.layer.msg(res.msg);
85
+                                layer.close(index);
86
+                                obj.del();
87
+                            }
88
+                        }
89
+                    });
90
+                    layer.close(index);
91
+                })
92
+            }
93
+        };
94
+
95
+        like.eventClick(active);
96
+
97
+
98
+        form.on("submit(search)", function (data) {
99
+            table.reload("like-table-lists", {
100
+                where: data.field,
101
+                page: {
102
+                    curr: 1
103
+                }
104
+            });
105
+        });
106
+
107
+
108
+        form.on("submit(clear-search)", function () {
109
+            $("#name").val("");
110
+            form.render("select");
111
+            table.reload("like-table-lists", {
112
+                where: {},
113
+                page: {
114
+                    curr: 1
115
+                }
116
+            });
117
+        });
118
+
119
+    })
120
+</script>

+ 84
- 0
app/shop/view/order/order_renew/pay_page.html 查看文件

@@ -0,0 +1,84 @@
1
+<!--
2
+ * @Author: xiaohai zmhwork@qq.com
3
+ * @Date: 2025-03-14 18:14:19
4
+ * @LastEditors: xiaohai zmhwork@qq.com
5
+ * @LastEditTime: 2025-03-17 17:32:59
6
+ * @FilePath: \opkpm\app\shop\view\order\order_renew\pay_page.html
7
+ * @Description: 续费套餐支付方式
8
+-->
9
+{layout name="layout2" /}
10
+
11
+<div class="layui-card layui-form" style="box-shadow:none;" id="payPage">
12
+    <div class="layui-card-body">
13
+        <div class="layui-form-item">
14
+            <label for="order_sn" class="layui-form-label"><span style="color:red;">*</span>订单编号:</label>
15
+            <div class="layui-input-block">
16
+                <input type="hidden" name="id" id="id" value="{$detail.id}" />
17
+                <input type="text" name="order_sn" id="order_sn" value="{$detail.order_sn}" lay-verType="tips"
18
+                    lay-verify="required" autocomplete="off" class="layui-input" readonly>
19
+            </div>
20
+        </div>
21
+
22
+        <div class="layui-form-item">
23
+            <label for="total_num" class="layui-form-label"><span style="color:red;">*</span>商品数量:</label>
24
+            <div class="layui-input-block">
25
+                <input type="text" name="total_num" id="total_num" value="{$detail.total_num}" lay-verType="tips"
26
+                    lay-verify="required" autocomplete="off" class="layui-input" readonly>
27
+            </div>
28
+        </div>
29
+
30
+        <div class="layui-form-item">
31
+            <label for="order_amount" class="layui-form-label"><span style="color:red;">*</span>应付金额:</label>
32
+            <div class="layui-input-block">
33
+                <input type="text" name="order_amount" id="order_amount" value="{$detail.order_amount}"
34
+                    lay-verType="tips" lay-verify="required" autocomplete="off" class="layui-input" readonly>
35
+            </div>
36
+        </div>
37
+
38
+        <div class="layui-form-item">
39
+            <label class="layui-form-label">支付方式</label>
40
+            <div class="layui-input-block">
41
+                <input type="radio" name="pay_way" value="1" title="微信支付" disabled>
42
+                <input type="radio" name="pay_way" value="2" title="支付宝支付" checked>
43
+            </div>
44
+        </div>
45
+
46
+        <div class="layui-form-item">
47
+            <div class="layui-input-block">
48
+                <button type="button" class="layui-btn" lay-event="pay" id="pay">点击支付</button>
49
+            </div>
50
+        </div>
51
+    </div>
52
+</div>
53
+
54
+<script>
55
+    layui.use(["table", "form", "jquery"], function () {
56
+        var table = layui.table;
57
+        var form = layui.form;
58
+        var $ = layui.jquery;
59
+
60
+        function payPage(id, pay_way) {
61
+            // 选择支付方式
62
+            like.ajax({
63
+                url: "{:url('order.OrderRenew/payWay')}",
64
+                data: {id: id, pay_way: pay_way},
65
+                type: "POST",
66
+                success: function (res) {
67
+                    if (res.code === 1) {
68
+                        $('#payPage').html(res.data.page);
69
+                    } else {
70
+                        layer.msg(res.msg);
71
+                    }
72
+                }
73
+            })
74
+        }
75
+
76
+
77
+        $("#pay").on("click", function () {
78
+            var id = $("#id").val();
79
+            var pay_way = $("input[name='pay_way']:checked").val();
80
+            payPage(id, pay_way);
81
+        });
82
+
83
+    })
84
+</script>

+ 130
- 0
app/shop/view/order/order_renew/renew_lists.html 查看文件

@@ -0,0 +1,130 @@
1
+{layout name="layout1" /}
2
+
3
+<div class="wrapper">
4
+    <div class="layui-card">
5
+        <!-- 操作提示 -->
6
+        <div class="layui-card-body">
7
+            <div class="layui-collapse" style="border:1px dashed #c4c4c4">
8
+                <div class="layui-colla-item">
9
+                    <h2 class="layui-colla-title like-layui-colla-title">操作提示</h2>
10
+                    <div class="layui-colla-content layui-show">
11
+                        <p>*续费套餐分为包月和按量付费。</p>
12
+                    </div>
13
+                </div>
14
+            </div>
15
+        </div>
16
+
17
+        <!-- 搜索区域 -->
18
+        <div class="layui-card-body layui-form">
19
+            <div class="layui-form-item">
20
+                <div class="layui-inline">
21
+                    <label for="name" class="layui-form-label">续费套餐:</label>
22
+                    <div class="layui-input-inline">
23
+                        <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
24
+                    </div>
25
+                </div>
26
+                <div class="layui-inline">
27
+                    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">搜索</a>
28
+                    <a class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</a>
29
+                </div>
30
+            </div>
31
+        </div>
32
+
33
+        <!-- 主体区域 -->
34
+        <div class="layui-card-body">
35
+            <table id="like-table-lists" lay-filter="like-table-lists"></table>
36
+            <script type="text/html" id="table-image">
37
+                {{#  if(d.image){ }}
38
+                    <img src="{{d.image}}" alt="图标" style="width:28px;height:28px;">
39
+                {{#  } }}
40
+            </script>
41
+            <script type="text/html" id="table-operation">
42
+                <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="buy">购买</a>
43
+            </script>
44
+        </div>
45
+
46
+    </div>
47
+</div>
48
+
49
+<script>
50
+    layui.use(["table", "form"], function () {
51
+        var table = layui.table;
52
+        var form = layui.form;
53
+
54
+
55
+        like.tableLists("#like-table-lists", "{:url()}", [
56
+            { field: "id", width: 60, title: "ID" }
57
+            , { field: "name", width: 260, align: "center", title: "续费套餐" }
58
+            , { field: "image", width: 120, align: "center", title: "套餐图片", templet: "#table-image" }
59
+            , { field: "type_str", width: 100, align: "center", title: "类型" }
60
+            , { field: "desc", width: 100, align: "center", title: "描述" }
61
+            , { field: "price", width: 100, align: "center", title: "价格" }
62
+            , { field: "op_count", width: 160, align: "center", title: "月份数/操作数" }
63
+            , { field: "status_str", width: 100, align: "center", title: "状态" }
64
+            , { field: "sort", width: 100, align: "center", title: "排序" }
65
+            , { title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#table-operation" }
66
+        ]);
67
+
68
+
69
+        var active = {
70
+            buy: function (obj) {
71
+                layer.open({
72
+                    type: 2
73
+                    , title: "购买续费套餐"
74
+                    , content: "{:url('order.OrderRenew/buy')}?id=" + obj.data.id
75
+                    , area: ["800px", "600px"]
76
+                    , btn: ["确定", "取消"]
77
+                    , yes: function (index, layero) {
78
+                        var iframeWindow = window["layui-layer-iframe" + index];
79
+                        var submit = layero.find("iframe").contents().find("#addSubmit");
80
+                        iframeWindow.layui.form.on("submit(addSubmit)", function (data) {
81
+                            data.field['renew_id'] = obj.data.id;
82
+                            like.ajax({
83
+                                url: "{:url('order.OrderRenew/add')}",
84
+                                data: data.field,
85
+                                type: "POST",
86
+                                success: function (res) {
87
+                                    if (res.code === 1) {
88
+                                        layer.close(index);
89
+                                        window.open("{:url('order.OrderRenew/payPage')}?id=" + res.data.id);
90
+                                    } else {
91
+                                        layer.msg(res.msg);
92
+                                    }
93
+                                }
94
+                            });
95
+                        });
96
+                        submit.trigger("click");
97
+                    }
98
+                });
99
+            },
100
+        };
101
+
102
+
103
+        
104
+
105
+        like.eventClick(active);
106
+
107
+
108
+        form.on("submit(search)", function (data) {
109
+            table.reload("like-table-lists", {
110
+                where: data.field,
111
+                page: {
112
+                    curr: 1
113
+                }
114
+            });
115
+        });
116
+
117
+
118
+        form.on("submit(clear-search)", function () {
119
+            $("#name").val("");
120
+            form.render("select");
121
+            table.reload("like-table-lists", {
122
+                where: {},
123
+                page: {
124
+                    curr: 1
125
+                }
126
+            });
127
+        });
128
+
129
+    })
130
+</script>

正在加载...
取消
保存