$params['property_head_id'], 'activity_name' => $params['activity_name'], 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0, 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0, 'block_data' => self::configureReservedField($params['block_data']??[], 'block_data'), 'coupon_data' => self::configureReservedField($params['coupon_data']??[], 'coupon_data'), 'url_page' => $params['url_page']??'', 'page_type' => $params['page_type']??0, 'images' => $params['images']??[], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2024/11/21 15:04 */ public static function edit(array $params): bool { Db::startTrans(); try { PropertyActivity::where('id', $params['id'])->update([ 'property_head_id' => $params['property_head_id'], 'activity_name' => $params['activity_name'], 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0, 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0, 'block_data' => json_encode(self::configureReservedField($params['block_data']??[], 'block_data')), 'coupon_data' => json_encode(self::configureReservedField($params['coupon_data']??[], 'coupon_data')), 'url_page' => $params['url_page']??'', 'page_type' => $params['page_type']??0, 'images' => json_encode($params['images']??[]), ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } public static function configureReservedField($data, $reserved_type,$reserved_field = []): array { if($reserved_type === 'block_data'){ $reserved_field = ['id','recommend_weight','goods_name']; foreach ($data as &$item) { foreach ($item['goods'] as &$good) { foreach ($good as $k=>$v) { if(!in_array($k,$reserved_field)){ unset($good[$k]); } } } } } if($reserved_type === 'coupon_data'){ $reserved_field = ['id','voucher_count','voucher_status','server_category_name','event_name','couponWithCategory','expire_time', 'amount_require','amount','max_deductible_price','discount_ratio','mold_type','coupon_type','code','remaining_count' ]; foreach ($data as &$item) { foreach ($item as $k=>$v) { if(!in_array($k,$reserved_field)){ unset($item[$k]); } } } } return $data??[]; } /** * @notes 删除 * @param array $params * @return bool * @author likeadmin * @date 2024/11/21 15:04 */ public static function delete(array $params): bool { return PropertyActivity::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/11/21 15:04 */ public static function detail($params): array { return PropertyActivity::findOrEmpty($params['id'])->toArray(); } public static function getQRCode($params,$url='weixiu.kyjlkj.com') { try { // $mnp_page = (isset($params['mnp_page']) && $params['mnp_page'])?urldecode($params['mnp_page']):env('miniprogram.property_activity_qrcode', ''); $mnp_page = 'pages/web_view/index'; if(empty($params['mnp_page'])){ throw new Exception('路径错误'); } $scene_page = (isset($params['mnp_page']) && $params['mnp_page'])? $params['mnp_page']:''; Log::info('getQRCode:'.rawurlencode($scene_page)); $response = (new WeChatMnpService())->getUnlimitedQRCode( 'page='.$scene_page.'&id='.$params['id'], $mnp_page, env('miniprogram.mini_env_version', 'release'), false ); Log::info('getQRCode:'.json_encode([$response])); $qrcode = $response->getContent(); if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){ mkdir('./uploads/wx_qrcode/'.date('Ymd')); } $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png'; file_put_contents($file_name, $qrcode); //$file_name = 'https://fushencdn.kyjlkj.com/uploads/miniqrcode/27f140aae615bbe16c1e888c14c9ab10.png'; return $url.'/'.$file_name; } catch (\Throwable $e) { Log::info('getQRCode:'.$e->getMessage()); return ''; } } public static function newDataExecute() { try { $activity_list = PropertyActivity::select()->toArray(); foreach ($activity_list as $item) { if(!empty($itemp['coupon_data'])){ continue; } $coupon_list = CouponRules::with(['couponWithCategory'=>function(Query $query){ $query->field('id,name'); }])->where('property_activity_id',$item['id']) ->field(['id','code', 'amount', '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']) ->select() ->toArray()??[]; foreach($coupon_list as $k => $v){ $v['goods_category_ids'] = array_column($v['couponWithCategory'],'id'); $coupon_list[$k] = $v; } if($coupon_list){ $data = [ 'coupon_data' => json_encode(self::configureReservedField($coupon_list??[], 'coupon_data')), ]; PropertyActivity::where('id',$item['id'])->update($data); } } return true; } catch (\Throwable $e) { return $e->getMessage(); } } }