| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | 
							- <?php
 
- namespace app\admin\controller\member;
 
- use app\admin\validate\member\RuleAddedValidate;
 
- use app\admin\validate\member\RulePricingValidate;
 
- use app\controller\Curd;
 
- use app\model\RuleAdded;
 
- use app\model\RuleAddedComponent;
 
- use app\model\RulePricing;
 
- use app\model\SysSerial;
 
- use support\exception\BusinessException;
 
- use support\Request;
 
- use support\Response;
 
- class RuleAddedController extends Curd
 
- {
 
-     public function __construct()
 
-     {
 
-         $this->model = new RuleAdded();
 
-         $this->validate = true;
 
-         $this->validateClass = new RuleAddedValidate();
 
-     }
 
-     public function select(Request $request): Response
 
-     {
 
-         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
 
-         $order = $request->get('order', 'desc');
 
-         $field = $field ?? 'rule_added_addtimes';
 
-         $query = $this->doSelect($where, $field, $order);
 
-         return $this->doFormat($query, $format, $limit);
 
-     }
 
-     public function selectList(Request $request)
 
-     {
 
-         $data = $this->model->where('rule_added_status', 'ACTIVED')
 
-             ->select('rule_added_id', 'rule_added_name')
 
-             ->get()
 
-             ->toArray();
 
-         return json_success('', $data);
 
-     }
 
-     public function info(Request $request): Response
 
-     {
 
-         $id = $request->get('rule_added_id');
 
-         $added = RuleAdded::find($id);
 
-         if (!$added) {
 
-             return json_fail('数据不存在');
 
-         }
 
-         $components = RuleAddedComponent::with(['goods', 'sku'])
 
-             ->where('join_component_rule_added_id', $id)
 
-             ->get()
 
-             ->toArray();
 
-         foreach ($components as &$component) {
 
-             if (!empty($component['sku']) && !empty($component['sku']['goods_sku_specs_json'])) {
 
-                 $specsJson = json_decode($component['sku']['goods_sku_specs_json'], true);
 
-                 $skuTitle = '';
 
-                 foreach ($specsJson as $item) {
 
-                     if (is_array($item)) {
 
-                         $item = implode(',', $item);
 
-                     }
 
-                     $skuTitle .= $item . '-';
 
-                 }
 
-                 $skuTitle = rtrim($skuTitle, '-');
 
-                 $component['sku']['goods_sku_title'] = $skuTitle;
 
-             }
 
-         }
 
-         return json_success('', $components);
 
-     }
 
-     protected function insertInput(Request $request): array
 
-     {
 
-         $data = $this->inputFilter($request->post());
 
-         $data['rule_added_id'] = "RA" . str_pad(SysSerial::getSerial(), 16, '0', STR_PAD_LEFT) . random_string(6, 'up');
 
-         return $data;
 
-     }
 
-     protected function updateInput(Request $request): array
 
-     {
 
-         $primary_key = $this->model->getKeyName();
 
-         $id = $request->post($primary_key);
 
-         $data = $this->inputFilter($request->post());
 
- //        if (!empty($data['rule_pricing_goods_json'])) {
 
- //            $data['rule_pricing_goods_json'] = json_encode(explode(',', $data['rule_pricing_goods_json']));
 
- //        } else {
 
- //            $data['rule_pricing_goods_json'] = '[]';
 
- //        }
 
-         $model = $this->model->find($id);
 
-         if (!$model) {
 
-             throw new BusinessException('记录不存在', 2);
 
-         }
 
-         unset($data[$primary_key]);
 
-         return [$id, $data];
 
-     }
 
- }
 
 
  |