zxhxx 3 years ago
parent
commit
e4f1b41ea0
4 changed files with 148 additions and 3 deletions
  1. 0 1
      app/models/store/StoreGp.php
  2. 3 2
      app/models/store/StoreOrder.php
  3. 26 0
      crmeb/jobs/GpJob.php
  4. 119 0
      crmeb/utils/Gp.php

+ 0 - 1
app/models/store/StoreGp.php

@@ -78,7 +78,6 @@ class StoreGp extends BaseModel
                             break;
                     }
                 }
-
             }
             $no_path = explode(",",$no_path);
             if (sizeof($no_path) > 3) {

+ 3 - 2
app/models/store/StoreOrder.php

@@ -11,6 +11,7 @@ use app\admin\model\store\StoreProductAttrValue;
 use app\admin\model\system\ShippingTemplatesFree;
 use app\admin\model\system\ShippingTemplatesRegion;
 use crmeb\basic\BaseModel;
+use crmeb\utils\Gp;
 use think\facade\Cache;
 use crmeb\traits\ModelTrait;
 use think\facade\Log;
@@ -839,14 +840,14 @@ class StoreOrder extends BaseModel
         $resPink = true;$resGp = true;
         $res1 = self::where('order_id', $orderId)->update(['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()]);//订单改为支付
         if ($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
-        if ($order->is_gp && $res1 && !$order->refund_status) $resGp = StoreGp::createGp($order);//创建公排
+        if ($order->is_gp && $res1 && !$order->refund_status) Gp::create($order->toArray());
         $oid = self::where('order_id', $orderId)->value('id');
         StoreOrderStatus::status($oid, 'pay_success', '用户付款成功');
         $now_money = User::where('uid', $order['uid'])->value('now_money');
         UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
         //支付成功后
         event('OrderPaySuccess', [$order, $formId]);
-        $res = $res1 && $resPink && $resGp;
+        $res = $res1 && $resPink ;
         return false !== $res;
     }
 

+ 26 - 0
crmeb/jobs/GpJob.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace crmeb\jobs;
+use app\models\store\StoreGp;
+use crmeb\interfaces\JobInterface;
+use think\queue\Job;
+
+class GpJob implements JobInterface
+{
+    public function fire(Job $job, $data): void
+    {
+        if($this->doorder($data))
+            $job->delete();
+        else {
+            $job->delete();
+        }
+    }
+
+    public function doorder($data)
+    {
+        StoreGp::createGp($data);
+        return true;
+    }
+
+}

+ 119 - 0
crmeb/utils/Gp.php

@@ -0,0 +1,119 @@
+<?php
+
+namespace crmeb\utils;
+
+use crmeb\traits\LogicTrait;
+use think\facade\Queue as QueueJob;
+
+/**
+ * Class Queue
+ * @package crmeb\utils
+ * @method $this setJobClassName(string $jobClassName); 设置任务类名
+ * @method $this setQueue(string $queue); 设置任务名
+ * @method $this setDelay(int $delay); 设置延迟时间
+ * @method $this setJobData(array $jobData); 设置任务参数
+ */
+class Gp
+{
+
+    use LogicTrait;
+
+    /**
+     * 任务类名
+     * @var string
+     */
+    protected $jobClassName = \crmeb\jobs\GpJob::class;
+
+    /**
+     * 多任务
+     * @var null
+     */
+    protected $task = null;
+
+    /**
+     * 任务参数
+     * @var array
+     */
+    protected $jobData = [
+        'beforeMethod' => 'doBeforeMethod', //默认任务执行前执行的方法
+        'method' => 'doDefaultJod', //默认任务执行方法
+        'data' => null, //执行任务需要的参数
+        'errorTimes' => 1, //任务执行错误最大次数
+        'release' => 0,//延迟执行秒数
+    ];
+
+    /**
+     * 任务名称
+     * @var string
+     */
+    protected $queue = 'GP';
+
+    /**
+     * 延迟执行秒数
+     * @var int
+     */
+    protected $delay = 0;
+
+    /**
+     * 规则
+     * @var array
+     */
+    protected $propsRule = [
+        'jobClassName' => null,
+        'queue' => null,
+        'delay' => null,
+        'jobData' => null,
+    ];
+
+    /**
+     * 创建定时执行任务
+     * @param $data
+     * @return mixed
+     */
+    public function push($data = null)
+    {
+        $this->merge($data);
+        return QueueJob::push($this->jobClassName, $this->jobData, $this->queue);
+    }
+
+    /**
+     * 创建延迟执行任务
+     * @param null $data
+     * @return mixed
+     */
+    public function later($data = null)
+    {
+        $this->merge($data);
+        return QueueJob::later($this->delay, $this->jobClassName, $this->jobData, $this->queue);
+    }
+
+    /**
+     * 合并处理参数
+     * @param $data
+     */
+    protected function merge($data)
+    {
+        if ($data) {
+            $this->jobData['data'] = $data;
+        }
+        if ($this->delay && !$this->jobData['release']) {
+            $this->jobData['release'] = $this->delay;
+        }
+        $this->jobClassName = $this->task ? $this->jobClassName . '@' . $this->task : $this->jobClassName;
+    }
+
+    /**
+     * 创建任务
+     * @param null $data
+     * @return mixed
+     */
+    public static function create($data = null)
+    {
+        $instance = self::instance();
+        if ($instance->delay) {
+            return $instance->later($data);
+        } else {
+            return $instance->push($data);
+        }
+    }
+}