|
@@ -302,17 +302,138 @@ class StoreLogic extends Logic
|
302
|
302
|
*/
|
303
|
303
|
public static function set($post)
|
304
|
304
|
{
|
|
305
|
+ //判断参数
|
|
306
|
+ if((int)$post['number'] < 0){
|
|
307
|
+ static::$error = "操作数量不能等于0!";
|
|
308
|
+ return false;
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ Db::startTrans();
|
305
|
312
|
try {
|
306
|
|
- Shop::update([
|
307
|
|
- 'is_distribution' => $post['is_distribution'] ?? 0,
|
308
|
|
- 'is_recommend' => $post['is_recommend'] ?? 0,
|
309
|
|
- 'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
|
310
|
|
- 'weight' => $post['weight'],
|
311
|
|
- 'tid' => $post['tid']
|
312
|
|
- ], ['id'=>$post['id']]);
|
|
313
|
+ //操作数大于0
|
|
314
|
+ if((int)$post['number'] > 0) {
|
|
315
|
+ $number = (int)$post['number'];
|
|
316
|
+ //计算
|
|
317
|
+ $item = Shop::where(['id' => $post['id']])->find();
|
|
318
|
+ if ((int)$item['hksy_type'] === 0) {
|
|
319
|
+ //包月
|
|
320
|
+ $expire_time = strtotime($item['expire_time']);
|
|
321
|
+ if ((int)$post['type'] === 0) {
|
|
322
|
+ //增加
|
|
323
|
+ $b = $number;
|
|
324
|
+ $b_str = '增加';
|
|
325
|
+ if ((int)$post['mouth'] === 0) {
|
|
326
|
+ //月份
|
|
327
|
+ $after_time = strtotime("+" . $number . " months", $expire_time);
|
|
328
|
+ $b_str .= $number . '个月';
|
|
329
|
+ $b_t = 0;
|
|
330
|
+ } else {
|
|
331
|
+ //天数
|
|
332
|
+ $after_time = strtotime("+" . $number . " day", $expire_time);
|
|
333
|
+ $b_str .= $number . '天';
|
|
334
|
+ $b_t = 1;
|
|
335
|
+ }
|
|
336
|
+ } else {
|
|
337
|
+ //减少
|
|
338
|
+ $b = -$number;
|
|
339
|
+ $b_str = '减少';
|
|
340
|
+ if ((int)$post['mouth'] === 0) {
|
|
341
|
+ //月份
|
|
342
|
+ $after_time = strtotime("-" . $number . " months", $expire_time);
|
|
343
|
+ $b_str .= $number . '个月';
|
|
344
|
+ $b_t = 0;
|
|
345
|
+ } else {
|
|
346
|
+ //天数
|
|
347
|
+ $after_time = strtotime("-" . $number . " day", $expire_time);
|
|
348
|
+ $b_str .= $number . '天';
|
|
349
|
+ $b_t = 1;
|
|
350
|
+ }
|
|
351
|
+ }
|
|
352
|
+ //操作结果测试
|
|
353
|
+ //echo $item['expire_time'].'<br/>';
|
|
354
|
+ //echo date("Y-m-d H:i:s",$after_time);die;
|
|
355
|
+ } else {
|
|
356
|
+ //按量付费
|
|
357
|
+ $hksy_count = (int)$item['hksy_count'];
|
|
358
|
+ if ((int)$post['type'] === 0) {
|
|
359
|
+ //增加
|
|
360
|
+ $after_hksy_count = $hksy_count + (int)$number;
|
|
361
|
+ $c = $number;
|
|
362
|
+ $c_str = '增加次数:' . $number;
|
|
363
|
+ } else {
|
|
364
|
+ //减少
|
|
365
|
+ if ($number > $hksy_count) {
|
|
366
|
+ //static::$error = "剩余数量不足于减少!";
|
|
367
|
+ //return false;
|
|
368
|
+ throw new \think\Exception('剩余数量不足于减少!');
|
|
369
|
+ }
|
|
370
|
+ $c = -$number;
|
|
371
|
+ $c_str = '减少次数:' . $number;
|
|
372
|
+ $after_hksy_count = $hksy_count - (int)$number;
|
|
373
|
+ }
|
|
374
|
+ //测试操作结果
|
|
375
|
+ //echo $hksy_count.'<br/>';
|
|
376
|
+ //echo $after_hksy_count;die;
|
|
377
|
+ }
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+ //增加日志
|
|
381
|
+ // 添加用户套餐时间或者数量
|
|
382
|
+ $hk = new ShopHkLog();
|
|
383
|
+ $hk->shop_id = $item['id'];
|
|
384
|
+ $hk->source_id = 0;
|
|
385
|
+ if ((int)$item['hksy_type'] === 0) {
|
|
386
|
+ //包月
|
|
387
|
+ $hk->source_type = 200;
|
|
388
|
+ $hk->change_count = $b;
|
|
389
|
+ $hk->before_date = date('Y-m-d H:i:s', $expire_time);
|
|
390
|
+ $hk->after_date = date('Y-m-d H:i:s', $after_time);
|
|
391
|
+ $hk->remark = '[后台操作],' . $b_str;
|
|
392
|
+ $hk->dw_type = $b_t; //单位类型
|
|
393
|
+ } else {
|
|
394
|
+ //按量付费
|
|
395
|
+ $hk->source_type = 100;
|
|
396
|
+ $hk->change_count = $c;
|
|
397
|
+ $hk->left_count = $after_hksy_count;
|
|
398
|
+ $hk->remark = '[后台操作],' . $c_str;
|
|
399
|
+ $hk->dw_type = 2;
|
|
400
|
+ }
|
|
401
|
+ $hk->save();
|
313
|
402
|
|
|
403
|
+ if ((int)$item['hksy_type'] === 0) {
|
|
404
|
+ Shop::update([
|
|
405
|
+ 'expire_time' => $after_time,
|
|
406
|
+ 'is_distribution' => $post['is_distribution'] ?? 0,
|
|
407
|
+ 'is_recommend' => $post['is_recommend'] ?? 0,
|
|
408
|
+ 'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
|
|
409
|
+ 'weight' => $post['weight'],
|
|
410
|
+ 'tid' => $post['tid']
|
|
411
|
+ ], ['id' => $post['id']]);
|
|
412
|
+ }else{
|
|
413
|
+ Shop::update([
|
|
414
|
+ 'hksy_count' => $after_hksy_count,
|
|
415
|
+ 'is_distribution' => $post['is_distribution'] ?? 0,
|
|
416
|
+ 'is_recommend' => $post['is_recommend'] ?? 0,
|
|
417
|
+ 'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
|
|
418
|
+ 'weight' => $post['weight'],
|
|
419
|
+ 'tid' => $post['tid']
|
|
420
|
+ ], ['id' => $post['id']]);
|
|
421
|
+ }
|
|
422
|
+ }else{
|
|
423
|
+ Shop::update([
|
|
424
|
+ 'is_distribution' => $post['is_distribution'] ?? 0,
|
|
425
|
+ 'is_recommend' => $post['is_recommend'] ?? 0,
|
|
426
|
+ 'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
|
|
427
|
+ 'weight' => $post['weight'],
|
|
428
|
+ 'tid' => $post['tid']
|
|
429
|
+ ], ['id' => $post['id']]);
|
|
430
|
+ }
|
|
431
|
+
|
|
432
|
+ Db::commit();
|
314
|
433
|
return true;
|
|
434
|
+
|
315
|
435
|
} catch (Exception $e) {
|
|
436
|
+ Db::rollback();
|
316
|
437
|
static::$error = $e->getMessage();
|
317
|
438
|
return false;
|
318
|
439
|
}
|