Explorar o código

工单详情可使用优惠券

whitefang hai 1 ano
pai
achega
47e39cfd52

+ 36 - 0
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -18,6 +18,8 @@ namespace app\adminapi\logic\works;
 use app\api\logic\PerformanceLogic;
 use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\logic\WorkerAccountLogLogic;
+use app\common\model\coupon\CouponCategory;
+use app\common\model\coupon\UserCoupon;
 use app\common\model\dict\DictData;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorkerAccountLog;
@@ -521,6 +523,40 @@ class ServiceWorkLogic extends BaseLogic
         return  $result;
     }
 
+    public static function getUserCouponDetails($params)
+    {
+        try{
+            $work = ServiceWork::where('id',$params['id'])->findOrEmpty();
+            if(!$work){
+                throw new \Exception('工单不存在');
+            }
+
+            $coupon_all_ids =UserCoupon::where('user_id',$work['user_id'])
+                ->where('voucher_count','>',0)
+                ->where('voucher_status',0)
+                ->where('expire_time','>',time())
+                ->column('coupon_id');
+            $coupon_ids = CouponCategory::where('goods_category_id',$work['goods_category_id'])->whereIn('coupon_id',$coupon_all_ids)->column('coupon_id');
+            $data = UserCoupon::where('user_id',$work['user_id'])
+                ->where('voucher_count','>',0)
+                ->where('voucher_status',0)
+                ->whereIn('coupon_id',$coupon_ids)
+                ->append(['discount_ratio_text'])
+                ->where('expire_time','>',time())
+                ->visible(['id','coupon_id','amount','amount_require','begin_use','discount_ratio','event_name','expire_time','max_deductible_price','server_category_name','mold_type'])
+                ->select()->toArray();
+            foreach($data as $k => $v){
+                $data[$k]['begin_use'] = date("Y-m-d H:i:s",$v['begin_use'] );
+                $data[$k]['expire_time'] = date("Y-m-d H:i:s",$v['expire_time'] );
+                $data[$k]['amount_require'] = '满'.$v['amount_require'].'可用';
+            }
+            return $data;
+        } catch(\Exception $e){
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
     public static function getDetailWorkServiceStatus($params)
     {
         $result = ServiceWork::where('id',$params['id'])->field('work_status,user_confirm_status,appointment_time,price_approval,appoint_approval')->findOrEmpty()->toArray();

+ 24 - 0
app/workerapi/controller/WorksController.php

@@ -4,6 +4,7 @@ namespace app\workerapi\controller;
 
 use app\adminapi\logic\master_worker\MasterWorkerLogic;
 use app\adminapi\logic\works\ServiceWorkLogic;
+use app\api\logic\UserCouponLogic;
 use app\common\model\works\IssueWork;
 use app\common\model\works\ReturnWork;
 use app\common\model\works\ServiceWork;
@@ -113,6 +114,29 @@ class WorksController extends BaseApiController
         }
     }
 
+    /**
+     * 获取用户优惠券
+     * @return \think\response\Json
+     */
+    public function getUserCoupons()
+    {
+        try {
+            $params = (new ServiceWorkValidate())->goCheck('detail',[
+                'user_id' => $this->userId,
+            ]);
+            if(empty($params['id'])){
+                $this->fail('参数错误');
+            }
+            $result = ServiceWorkLogic::getUserCouponDetails($params);
+            if (false === $result) {
+                return $this->fail(ServiceWorkLogic::getError());
+            }
+            return $this->data($result);
+        } catch (Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+
     /**
      *
      * @return \think\response\Json