Просмотр исходного кода

Merge branch 'v4.7.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v4.7.0dev

From-wh 2 лет назад
Родитель
Сommit
143f636bb6

+ 13 - 1
crmeb/app/api/controller/v1/TimerController.php

@@ -10,15 +10,27 @@ use app\services\order\StoreOrderServices;
 use app\services\order\StoreOrderTakeServices;
 use app\services\product\product\StoreProductServices;
 use app\services\system\attachment\SystemAttachmentServices;
+use app\services\system\timer\SystemTimerServices;
 
 class TimerController
 {
+    /**
+     * 定时任务调用接口
+     * @author 吴汐
+     * @email 442384644@qq.com
+     * @date 2023/02/17
+     */
+    public function timerRun()
+    {
+        app()->make(SystemTimerServices::class)->timerRun();
+    }
+
     /**
      * 检测定时任务是否正常,必须6秒执行一次
      */
     public function timerCheck()
     {
-        file_put_contents(runtime_path() . '.timer', time());
+        file_put_contents(root_path() . 'runtime/.timer', time());
     }
 
     /**

+ 2 - 0
crmeb/app/api/route/v1.php

@@ -390,6 +390,8 @@ Route::group(function () {
     Route::get('get_default_lang_type', 'v1.PublicController/getDefaultLangType')->name('getLangJson');
 
     /** 定时任务接口 */
+    //定时任务调用接口
+    Route::get('timer/run', 'v1.TimerController/timerRun')->name('timerRun');
     //检测定时任务接口
     Route::get('timer/check', 'v1.TimerController/timerCheck')->name('timerCheck');
     //未支付自动取消订单

+ 35 - 42
crmeb/app/listener/timer/SystemTimer.php

@@ -19,9 +19,8 @@ class SystemTimer implements ListenerInterface
 {
     public function handle($event): void
     {
-
         new Crontab('*/6 * * * * *', function () {
-            file_put_contents(runtime_path() . '.timer', time());
+            file_put_contents(root_path() . 'runtime/.timer', time());
         });
 
         /** @var SystemTimerServices $systemTimerServices */
@@ -30,13 +29,9 @@ class SystemTimer implements ListenerInterface
         foreach ($list as &$item) {
             //获取定时任务时间字符串
             $timeStr = $this->getTimerStr($item);
-//            Log::error('mark:'.$item['mark']);
-//            Log::error($timeStr);
-
+            //未支付自动取消订单
             if ($item['mark'] == 'order_cancel') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔30秒执行一次自动取消订单 '.date('Y-m-d H:i:s'));
-                    //未支付自动取消订单
                     try {
                         /** @var StoreOrderServices $orderServices */
                         $orderServices = app()->make(StoreOrderServices::class);
@@ -46,11 +41,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //拼团到期订单处理
             if ($item['mark'] == 'pink_expiration') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔1分钟执行一次拼团到期订单处理 '.date('Y-m-d H:i:s'));
-                    //拼团到期订单处理
                     try {
                         /** @var StorePinkServices $storePinkServices */
                         $storePinkServices = app()->make(StorePinkServices::class);
@@ -60,11 +53,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //自动解绑上级绑定
             if ($item['mark'] == 'agent_unbind') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔1分钟执行一次自动解除上级绑定 '.date('Y-m-d H:i:s'));
-                    //自动解绑上级绑定
                     try {
                         /** @var AgentManageServices $agentManage */
                         $agentManage = app()->make(AgentManageServices::class);
@@ -74,11 +65,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //更新直播商品状态
             if ($item['mark'] == 'live_product_status') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔3分钟执行一次更新直播商品状态 '.date('Y-m-d H:i:s'));
-                    //更新直播商品状态
                     try {
                         /** @var LiveGoodsServices $liveGoods */
                         $liveGoods = app()->make(LiveGoodsServices::class);
@@ -88,11 +77,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //更新直播间状态
             if ($item['mark'] == 'live_room_status') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔3分钟执行一次更新直播间状态 '.date('Y-m-d H:i:s'));
-                    //更新直播间状态
                     try {
                         /** @var LiveRoomServices $liveRoom */
                         $liveRoom = app()->make(LiveRoomServices::class);
@@ -102,11 +89,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //自动收货
             if ($item['mark'] == 'take_delivery') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔5分钟执行一次自动收货 '.date('Y-m-d H:i:s'));
-                    //自动收货
                     try {
                         /** @var StoreOrderTakeServices $services */
                         $services = app()->make(StoreOrderTakeServices::class);
@@ -116,11 +101,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //查询预售到期商品自动下架
             if ($item['mark'] == 'advance_off') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔5分钟执行一次查询预售到期商品自动下架 '.date('Y-m-d H:i:s'));
-                    //查询预售到期商品自动下架
                     try {
                         /** @var StoreProductServices $product */
                         $product = app()->make(StoreProductServices::class);
@@ -130,11 +113,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //自动好评
             if ($item['mark'] == 'product_replay') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每隔5分钟执行一次自动好评 '.date('Y-m-d H:i:s'));
-                    //自动好评
                     try {
                         /** @var StoreOrderServices $orderServices */
                         $orderServices = app()->make(StoreOrderServices::class);
@@ -144,11 +125,9 @@ class SystemTimer implements ListenerInterface
                     }
                 });
             }
-
+            //清除昨日海报
             if ($item['mark'] == 'clear_poster') {
                 new Crontab($timeStr, function () {
-//                    Log::error('每天0时30分0秒执行一次清除昨日海报 '.date('Y-m-d H:i:s'));
-                    //清除昨日海报
                     try {
                         /** @var SystemAttachmentServices $attach */
                         $attach = app()->make(SystemAttachmentServices::class);
@@ -160,33 +139,47 @@ class SystemTimer implements ListenerInterface
             }
         }
     }
-
+    /**
+     *  0   1   2   3   4   5
+        |   |   |   |   |   |
+        |   |   |   |   |   +------ day of week (0 - 6) (Sunday=0)
+        |   |   |   |   +------ month (1 - 12)
+        |   |   |   +-------- day of month (1 - 31)
+        |   |   +---------- hour (0 - 23)
+        |   +------------ min (0 - 59)
+        +-------------- sec (0-59)[可省略,如果没有0位,则最小时间粒度是分钟]
+     */
+    /**
+     * 获取定时任务时间表达式
+     * @param $data
+     * @return string
+     */
     public function getTimerStr($data): string
     {
         $timeStr = '';
         switch ($data['type']) {
-            case 1:
+            case 1:// 每隔几秒
                 $timeStr = '*/' . $data['second'] . ' * * * * *';
                 break;
-            case 2:
+            case 2:// 每隔几分
                 $timeStr = '0 */' . $data['minute'] . ' * * * *';
                 break;
-            case 3:
-                $timeStr = '0 0 */' . $data['hour'] . ' * * *';
+            case 3:// 每隔几时第几分钟执行
+                $timeStr = '0 ' . $data['minute'] . ' */' . $data['hour'] . ' * * *';
                 break;
-            case 4:
-                $timeStr = '0 0 0 */' . $data['day'] . ' * *';
+            case 4:// 每隔几日第几小时第几分钟执行
+                $timeStr = '0 ' . $data['minute'] . ' ' . $data['hour'] . ' */' . $data['day'] . ' * *';
                 break;
-            case 5:
+            case 5:// 每日几时几分几秒
                 $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' * * *';
                 break;
-            case 6:
+            case 6:// 每周周几几时几分几秒
                 $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' * * ' . ($data['week'] == 7 ? 0 : $data['week']);
                 break;
-            case 7:
+            case 7:// 每月几日几时几分几秒
                 $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' ' . $data['day'] . ' * *';
                 break;
         }
         return $timeStr;
     }
-}
+}

+ 17 - 2
crmeb/app/services/activity/combination/StorePinkServices.php

@@ -151,8 +151,23 @@ class StorePinkServices extends BaseServices
         $where['cid'] = $id;
         $where['k_id'] = 0;
         $where['is_refund'] = 0;
-        $list = $this->dao->pinkList($where);
-        $ids = array_column($list, 'id');
+        $pinkList = $this->dao->pinkList($where);
+        $ids = array_column($pinkList, 'id');
+        $orderIdKey = array_column($pinkList, 'order_id_key');
+        $refunList = [];
+        if ($orderIdKey) {
+            $refunList = app()->make(StoreOrderRefundServices::class)->getColumn([['store_order_id', 'in', $orderIdKey]], 'id', 'store_order_id');
+        }
+        if ($refunList) {
+            $list = [];
+            foreach ($pinkList as $item) {
+                if (!isset($refunList[$item['order_id_key']])) {
+                    $list[] = $item;
+                }
+            }
+        } else {
+            $list = $pinkList;
+        }
         $counts = $this->dao->getPinkPeopleCount($ids);
         if ($type) {
             $pinkAll = [];

+ 1 - 0
crmeb/app/services/order/StoreOrderServices.php

@@ -53,6 +53,7 @@ use think\facade\Log;
  * @method getTrendData($time, $type, $timeType, $str) 用户趋势
  * @method getRegion($time, $channelType) 地域统计
  * @method getProductTrend($time, $timeType, $field, $str) 商品趋势
+ * @method getList(array $where, array $field, int $page = 0, int $limit = 0, array $with = [])
  */
 class StoreOrderServices extends BaseServices
 {

+ 60 - 3
crmeb/app/services/system/timer/SystemTimerServices.php

@@ -3,7 +3,15 @@
 namespace app\services\system\timer;
 
 use app\dao\system\timer\SystemTimerDao;
+use app\services\activity\combination\StorePinkServices;
+use app\services\activity\live\LiveGoodsServices;
+use app\services\activity\live\LiveRoomServices;
+use app\services\agent\AgentManageServices;
 use app\services\BaseServices;
+use app\services\order\StoreOrderServices;
+use app\services\order\StoreOrderTakeServices;
+use app\services\product\product\StoreProductServices;
+use app\services\system\attachment\SystemAttachmentServices;
 use crmeb\exceptions\AdminException;
 
 class SystemTimerServices extends BaseServices
@@ -121,7 +129,7 @@ class SystemTimerServices extends BaseServices
     }
 
     /**
-     * 计算定时任务下次执行时间(弃用)
+     * 计算定时任务下次执行时间
      * @param $data
      * @param int $time
      * @return false|float|int|mixed
@@ -137,10 +145,10 @@ class SystemTimerServices extends BaseServices
                 $cycle_time = $time + ($data['minute'] * 60);
                 break;
             case 3: // 每隔几时
-                $cycle_time = $time + ($data['hour'] * 3600);
+                $cycle_time = $time + ($data['hour'] * 3600) + ($data['minute'] * 60);
                 break;
             case 4: // 每隔几日
-                $cycle_time = $time + ($data['day'] * 86400);
+                $cycle_time = $time + ($data['day'] * 86400) + ($data['hour'] * 3600) + ($data['minute'] * 60);
                 break;
             case 5: // 每日几时几分几秒
                 $cycle_time = strtotime(date('Y-m-d ' . $data['hour'] . ':' . $data['minute'] . ':' . $data['second'], time()));
@@ -184,4 +192,53 @@ class SystemTimerServices extends BaseServices
         }
         return $cycle_time;
     }
+
+    /**
+     * 执行任务
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author 吴汐
+     * @email 442384644@qq.com
+     * @date 2023/02/17
+     */
+    public function timerRun()
+    {
+        file_put_contents(root_path() . 'runtime/.timer', time()); //检测定时任务是否正常
+        $list = $this->dao->selectList(['is_open' => 1, 'is_del' => 0])->toArray();
+        foreach ($list as $item) {
+            if ($item['next_execution_time'] < time()) {
+                if ($item['mark'] == 'order_cancel') {
+                    //未支付自动取消订单
+                    app()->make(StoreOrderServices::class)->orderUnpaidCancel();
+                } elseif ($item['mark'] == 'pink_expiration') {
+                    //拼团到期订单处理
+                    app()->make(StorePinkServices::class)->statusPink();
+                } elseif ($item['mark'] == 'agent_unbind') {
+                    //自动解绑上级绑定
+                    app()->make(AgentManageServices::class)->removeSpread();
+                } elseif ($item['mark'] == 'live_product_status') {
+                    //更新直播商品状态
+                    app()->make(LiveGoodsServices::class)->syncGoodStatus();
+                } elseif ($item['mark'] == 'live_room_status') {
+                    //更新直播间状态
+                    app()->make(LiveRoomServices::class)->syncRoomStatus();
+                } elseif ($item['mark'] == 'take_delivery') {
+                    //自动收货
+                    app()->make(StoreOrderTakeServices::class)->autoTakeOrder();
+                } elseif ($item['mark'] == 'advance_off') {
+                    //查询预售到期商品自动下架
+                    app()->make(StoreProductServices::class)->downAdvance();
+                } elseif ($item['mark'] == 'product_replay') {
+                    //自动好评
+                    app()->make(StoreOrderServices::class)->autoComment();
+                } elseif ($item['mark'] == 'clear_poster') {
+                    //清除昨日海报
+                    app()->make(SystemAttachmentServices::class)->emptyYesterdayAttachment();
+                }
+                //写入本次执行时间和下次执行时间
+                $this->dao->update(['mark' => $item['mark']], ['last_execution_time' => time(), 'next_execution_time' => $this->getTimerCycleTime($item)]);
+            }
+        }
+    }
 }

+ 1 - 1
crmeb/app/services/user/UserBillServices.php

@@ -1185,7 +1185,7 @@ class UserBillServices extends BaseServices
     {
         /** @var UserServices $userService */
         $userService = app()->make(UserServices::class);
-        if (!$userService->getUserInfo($uid)) {
+        if (!$userService->getUserInfo($uid, 'uid')) {
             throw new ApiException(100026);
         }
         $result = ['list' => [], 'time' => [], 'count' => 0];

+ 2 - 5
crmeb/app/services/user/UserServices.php

@@ -9,8 +9,6 @@
 // | Author: CRMEB Team <admin@crmeb.com>
 // +----------------------------------------------------------------------
 
-//declare (strict_types=1);
-
 namespace app\services\user;
 
 use app\jobs\UserJob;
@@ -44,7 +42,6 @@ use think\Exception;
 use think\facade\Route as Url;
 
 /**
- *
  * Class UserServices
  * @package app\services\user
  * @method array getUserInfoArray(array $where, string $field, string $key) 根据条件查询对应的用户信息以数组形式返回
@@ -1597,7 +1594,7 @@ class UserServices extends BaseServices
      */
     public function spread(int $uid, int $spreadUid, $code)
     {
-        $userInfo = $this->dao->value(['uid' => $uid], 'uid,spread_uid,spread_time,add_time,last_time');
+        $userInfo = $this->dao->getOne(['uid' => $uid], 'uid,spread_uid,spread_time,add_time,last_time');
         if (!$userInfo) {
             throw new ApiException(100026);
         }
@@ -1635,7 +1632,7 @@ class UserServices extends BaseServices
                 $check = true;
             }
         }
-        if ($userInfo['uid'] == $userSpreadUid || $userInfo['spread_uid'] == $spreadUid) $check = false;
+        if ($userInfo['uid'] == $spreadUid || $userInfo['spread_uid'] == $userSpreadUid) $check = false;
         if ($check) {
             $spreadInfo = $this->dao->get($spreadUid, ['division_id', 'agent_id', 'staff_id']);
             $data = [];

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
crmeb/public/install/crmeb.sql


+ 8 - 8
template/admin/src/pages/system/crontab/createModal.vue

@@ -40,13 +40,13 @@
                 <span class="suffix">日</span>
               </div>
             </Col>
-            <Col v-if="[3, 5, 6, 7].includes(formValidate.type)" span="4">
+            <Col v-if="[3, 4, 5, 6, 7].includes(formValidate.type)" span="4">
               <div class="input-number-wrapper">
                 <InputNumber v-model="formValidate.hour" :max="23" :min="0"></InputNumber>
                 <span class="suffix">时</span>
               </div>
             </Col>
-            <Col span="4" v-if="[2, 5, 6, 7].includes(formValidate.type)">
+            <Col span="4" v-if="[2, 3, 4, 5, 6, 7].includes(formValidate.type)">
               <div class="input-number-wrapper">
                 <InputNumber
                   v-model="formValidate.minute"
@@ -170,10 +170,10 @@ export default {
             this.trip = `每隔${nVal.minute}分钟执行一次`;
             break;
           case 3:
-            this.trip = `每隔${nVal.hour}小时执行一次`;
+            this.trip = `每隔${nVal.hour}小时的${nVal.minute}分执行一次`;
             break;
           case 4:
-            this.trip = `每隔${nVal.day}天执行一次`;
+            this.trip = `每隔${nVal.day}天的${nVal.hour}时${nVal.minute}分执行一次`;
             break;
           case 5:
             this.trip = `每天${nVal.hour}时${nVal.minute}分${nVal.second}秒执行一次`;
@@ -306,10 +306,10 @@ export default {
     line-height: 33px;
     color: #333333;
   }
+}
 
+.trip {
+  padding-left: 15px;
+  color: #aaa;
 }
- .trip{
-    padding-left 15px
-    color #aaa
-  }
 </style>

+ 2 - 2
template/uni-app/pages/users/promoter-order/index.vue

@@ -104,7 +104,7 @@
 		data() {
 			return {
 				page: 1,
-				limit: 5,
+				limit: 8,
 				status: false,
 				recordList: [],
 				times: [],
@@ -173,7 +173,7 @@
 						}
 					}
 					that.count = res.data.count || 0;
-					that.status = res.data.list.length < 5;
+					that.status = res.data.list.length < 8;
 					that.page += 1;
 				});
 			}