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

Merge branch 'master' of e.coding.net:zdap/weixiu/weixiu_api into equity-m

liugc 1 год назад
Родитель
Сommit
4f8d510f4c

+ 9 - 1
app/adminapi/lists/coupon/CouponRulesLists.php

@@ -61,6 +61,15 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
         if(isset($this->params['min_voucher_count']) && is_numeric($this->params['min_voucher_count'])){
             $where[] = ['voucher_count', '>=', $this->params['min_voucher_count']];
         }
+        if (isset($this->params['labels']) && !empty($this->params['labels'])) {
+            $sqls = [];
+            foreach ($this->params['labels'] as $item) {
+                $sqls[] = "FIND_IN_SET({$item}, labels) > 0";
+            }
+            $query_sql = implode(' OR ', $sqls);
+            $period_ids = CouponRules::where('labels','<>', '')->whereRaw($query_sql)->column('id');
+            $where[] = [ 'id','IN',$period_ids?:[0]];
+        }
         if(isset($this->params['max_voucher_count']) && is_numeric($this->params['max_voucher_count'])){
             $where[] = ['voucher_count', '<=', $this->params['max_voucher_count']];
         }
@@ -107,7 +116,6 @@ class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterfac
             $query->field('id,goods_name');
         }])->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->field(['id','code', 'amount', 'coupon_target', 'coupon_type','amount_require', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count','remaining_count','property_activity_id'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 9 - 2
app/adminapi/lists/master_worker/MasterWorkerServiceOrderLists.php

@@ -3,6 +3,7 @@ namespace app\adminapi\lists\master_worker;
 
 use app\adminapi\lists\BaseAdminDataLists;
 use app\common\lists\ListsSearchInterface;
+use app\common\model\goods_category\GoodsCategory;
 use app\common\model\master_worker\MasterWorker;
 use think\facade\Db;
 use think\facade\Log;
@@ -90,8 +91,9 @@ class MasterWorkerServiceOrderLists extends BaseAdminDataLists implements ListsS
     public function lists(): array
     {
         $queryWhere = $this->queryWhere();
-        return Db::name('master_worker')->alias('a')->field([
-                'a.id','a.real_name','a.nickname','a.worker_number','a.recruiting_behalf','a.mobile','a.cooperation',
+        $lists = Db::name('master_worker')->alias('a')->field([
+                'a.id','a.real_name','a.nickname','a.worker_number','a.recruiting_behalf','a.mobile','a.cooperation','a.category_ids',
+                Db::raw("COUNT(b.id) AS all_count"),
                 Db::raw("SUM(CASE WHEN b.service_status = 3 THEN 1 ELSE 0 END) AS success_count"),
                 Db::raw("SUM(CASE WHEN b.service_status = 4 OR b.service_status = 5 THEN 1 ELSE 0 END) AS fail_count"),
                 Db::raw("SUM(b.work_total) work_total"),
@@ -103,6 +105,11 @@ class MasterWorkerServiceOrderLists extends BaseAdminDataLists implements ListsS
             ->order('a.id desc')
             ->limit($this->limitOffset, $this->limitLength)
             ->select()->toArray();
+        $categoryData = GoodsCategory::select()->toArray();
+        foreach ($lists as &$item) {
+            $item['category_name'] = implode('、',array_column(get_parent_info($categoryData,explode(',',$item['category_ids'])),'name'));
+        }
+        return $lists;
     }
 
 

+ 5 - 0
app/adminapi/lists/works/ServiceWorkLists.php

@@ -17,6 +17,7 @@ namespace app\adminapi\lists\works;
 
 use app\adminapi\lists\BaseAdminDataLists;
 use app\common\model\goods_category\GoodsCategory;
+use app\common\model\master_worker\MasterWorker;
 use app\common\model\works\ServiceWork;
 use app\common\lists\ListsSearchInterface;
 use think\db\Query;
@@ -48,6 +49,10 @@ class ServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterfac
 
     public function queryWhere(){
         $where = [];
+        if (isset($this->params['master_worker_name']) && !empty($this->params['master_worker_name'])) {
+            $master_worker_ids = MasterWorker::where([['nickname|worker_number|mobile', 'like','%' .$this->params['master_worker_name'] . '%']])->column('id')??[0];
+            $where[] = ['master_worker_id','in' ,$master_worker_ids];
+        }
         if(isset($this->params['dispatch_time']) && !empty($this->params['dispatch_time'])){
             $time = [strtotime($this->params['dispatch_time'][0]), strtotime($this->params['dispatch_time'][1])];
             $where[] = ['dispatch_time', 'between', $time];

+ 2 - 0
app/adminapi/logic/coupon/CouponRulesLogic.php

@@ -60,6 +60,7 @@ class CouponRulesLogic extends BaseLogic
                 'voucher_count' => $params['voucher_count'],
                 'remaining_count' => $params['voucher_count'],
                 'property_activity_id' => $params['property_activity_id']??0,
+                'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
             ]);
             if(!empty($params['goods_category_ids'])){
                 $categoryArr = [];
@@ -111,6 +112,7 @@ class CouponRulesLogic extends BaseLogic
                 'voucher_count' => $params['voucher_count'],
                 'remaining_count' => $params['remaining_count'],
                 'property_activity_id' => $params['property_activity_id']??0,
+                'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
             ]);
             CouponCategory::where('coupon_id',$params['id'])->delete();
             if(!empty($params['goods_category_ids'])){

+ 32 - 1
app/adminapi/logic/goods/GoodsLogic.php

@@ -43,6 +43,10 @@ class GoodsLogic extends BaseLogic
     {
         Db::startTrans();
         try {
+            if((!$params['type'] || !$params['rate']) && $params['goods_status']==1){
+                throw new Exception('商品规格的绩效未配置,不允许上架');
+            }
+
             $params['goods_category_id'] = end($params['goods_category_ids']);
             if ($params['is_type'] == 1) {
                 $params['is_agent'] = 1;
@@ -54,7 +58,7 @@ class GoodsLogic extends BaseLogic
                 $params['is_agent'] = 0;
                 $params['is_activity'] = 0;
             }
-            Goods::create([
+            $goods = Goods::create([
                 'goods_category_ids' => $params['goods_category_ids'],
                 'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'goods_category_id' => $params['goods_category_id'],
@@ -86,8 +90,34 @@ class GoodsLogic extends BaseLogic
                 'is_activity' => $params['is_activity'] ??0,
                 'property_activity_id' => $params['property_activity_id'] ??0,
                 'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
+                'activity_service_fee' => $params['activity_service_fee'] ??'',
             ]);
 
+            //更新绩效规则
+            if(in_array($params['type'],[0,1,2])){
+                // 0-1
+                if($params['rate']>1){
+                    throw new Exception('商品绩效比率不能大于1');
+                }
+            }
+            if(in_array($params['type'],[3])){
+                // ≥1
+                if($params['rate']<1){
+                    throw new Exception('金额不能小于1');
+                }
+            }
+            $rule = PerformanceRules::where(['goods_id'=>$goods->id])->findOrEmpty();
+            if(!$rule->isEmpty()){
+                $rule->type = $params['type'];
+                $rule->rate = $params['rate'];
+            }else{
+                $rule = new PerformanceRules();
+                $rule->goods_id = $goods->id;
+                $rule->type = $params['type'];
+                $rule->rate = $params['rate'];
+            }
+            $rule->save();
+
             Db::commit();
             return true;
         } catch (\Exception $e) {
@@ -157,6 +187,7 @@ class GoodsLogic extends BaseLogic
                 'is_activity' => $params['is_activity'] ??0,
                 'property_activity_id' => $params['property_activity_id'] ??0,
                 'labels' => (isset($params['labels']) && $params['labels'])?implode(',',$params['labels']):'',
+                'activity_service_fee' => $params['activity_service_fee'] ??'',
             ]);
 
             //更新绩效规则

+ 1 - 1
app/adminapi/logic/property/PropertyActivityLogic.php

@@ -101,7 +101,7 @@ class PropertyActivityLogic extends BaseLogic
     public static function configureReservedField($data, $reserved_type,$reserved_field = []): array
     {
         if($reserved_type === 'block_data'){
-            $reserved_field = ['id','recommend_weight','goods_name'];
+            $reserved_field = ['id','recommend_weight','goods_name','base_service_fee','service_total','service_fee','activity_service_fee'];
             foreach ($data as $key => &$item) {
                 $data[$key]['block_key'] = $key+1;
                 foreach ($item['goods'] as &$good) {

+ 8 - 0
app/api/logic/ActivityLogic.php

@@ -3,6 +3,7 @@ namespace app\api\logic;
 
 use app\adminapi\logic\property\PropertyUserLogic;
 use app\common\logic\BaseLogic;
+use app\common\model\coupon\CouponGoods;
 use app\common\model\coupon\CouponRules;
 use app\common\model\goods\Goods;
 use app\common\model\goods_category\GoodsCategory;
@@ -91,7 +92,14 @@ class ActivityLogic extends BaseLogic
             array_multisort(array_column($v['goods'], 'recommend_weight'), SORT_DESC, $v['goods']);
             if(!empty($v['goods'])){
                 foreach ($v['goods'] as &$item){
+                    $reserved_fields = $item;
                     $item = Goods::findOrEmpty($item['id'])->toArray();
+                    $item['code'] = '';
+                    $goods_coupon_id = CouponGoods::where(['goods_id'=>$item['id']])->valeue('coupon_id')??0;
+                    $goods_coupon_id && $item['code'] =  CouponRules::where(['id'=>$goods_coupon_id])->valeue('code')??'';
+                    foreach ($reserved_fields as $field => $value) {
+                        !empty($value) && $item[$field] = $value;
+                    }
 
                     // 临时改价 11-28
                     $item['service_fee'] = $item['base_service_fee'];

+ 32 - 1
app/common.php

@@ -135,7 +135,38 @@ function get_tree_ids($data,$pid = 0, $idField = 'id',$pidField = 'pid')
     }
     return $child;
 }
-
+function get_top_parent_info($data, $id, $idField = 'id', $pidField = 'pid')
+{
+    foreach ($data as $item) {
+        if ($item[$idField] == $id) {
+            if ($item[$pidField] == 0) {
+                return $item;
+            } else {
+                return get_top_parent_info($data, $item[$pidField], $idField, $pidField);
+            }
+        }
+    }
+    return null;
+}
+/**
+ * 根据子集的值获取所有最高父级信息
+ * @param $data
+ * @param $pid
+ * @param $idField
+ * @param $pidField
+ * @return array
+ */
+function get_parent_info($data,$ids = [])
+{
+    $res = [];
+    foreach ($ids as $item) {
+        $topParentInfo = get_top_parent_info($data, $item);
+        if ($topParentInfo !== null) {
+            $res[$topParentInfo['id']] = $topParentInfo;
+        }
+    }
+    return $res;
+}
 
 /**
  * @notes 删除目标目录

+ 10 - 0
app/common/logic/TableDataLogic.php

@@ -72,4 +72,14 @@ class TableDataLogic extends BaseLogic
     {
         return Labels::where('id','>',0)->where('label_type',2)->field('id,label_name as name,id as value,"data_table_masterWorkerLabels" as type_value')->select()->toArray();
     }
+    /**
+     * @notes 优惠券标签列表
+     */
+    public static function couponLabels()
+    {
+        return Labels::where('id','>',0)->where('label_type',3)->field('id,label_name as name,id as value,"data_table_couponLabels" as type_value')->select()->toArray();
+    }
+
+
+
 }

+ 4 - 1
app/common/model/coupon/CouponRules.php

@@ -54,5 +54,8 @@ class CouponRules extends BaseModel
     {
         return $this->hasOne(CouponCategory::class, 'coupon_id', 'id');
     }
-
+    public function getLabelsAttr($value)
+    {
+        return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
+    }
 }

+ 4 - 0
app/common/model/master_worker/MasterWorker.php

@@ -107,4 +107,8 @@ class MasterWorker extends BaseModel
     {
         return $this->hasOne(BankAccount::class, 'worker_id', 'id');
     }
+    public function getLabelsAttr($value)
+    {
+        return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
+    }
 }