93 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| 
 | |
| namespace app\shop\logic;
 | |
| 
 | |
| 
 | |
| use app\common\basics\Logic;
 | |
| use app\common\enum\ShopEnum;
 | |
| use app\common\model\shop\Shop;
 | |
| use app\common\server\UrlServer;
 | |
| 
 | |
| class StoreLogic extends Logic
 | |
| {
 | |
|     /**
 | |
|      * @Notes: 获取商家详细
 | |
|      * @Author: 张无忌
 | |
|      * @param $shop_id
 | |
|      * @return array
 | |
|      */
 | |
|     public static function detail($shop_id)
 | |
|     {
 | |
|         $model = new Shop();
 | |
|         $detail = $model->field(true)
 | |
|             ->with(['category'])
 | |
|             ->json(['other_qualifications'],true)
 | |
|             ->findOrEmpty($shop_id)->toArray();
 | |
| 
 | |
|         $detail['category'] = $detail['category']['name'] ?? '未知';
 | |
|         $detail['type'] = ShopEnum::getShopTypeDesc($detail['type']);
 | |
|         $detail['run_start_time'] = $detail['run_start_time'] ? date('H:i:s', $detail['run_start_time']) : '';
 | |
|         $detail['run_end_time'] = $detail['run_end_time'] ? date('H:i:s', $detail['run_end_time']) : '';
 | |
|         $detail['business_license'] = $detail['business_license'] ? UrlServer::getFileUrl($detail['business_license']) : '';
 | |
|         if (!empty($detail['other_qualifications'])) {
 | |
|             foreach ($detail['other_qualifications'] as &$val) {
 | |
|                 $val = UrlServer::getFileUrl($val);
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
|         return $detail;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @Notes: 修改商家信息
 | |
|      * @Author: 张无忌
 | |
|      * @param $post
 | |
|      * @return bool
 | |
|      */
 | |
|     public static function edit($post)
 | |
|     {
 | |
|         try {
 | |
|             $num = count($post['other_qualifications'] ?? []);
 | |
|             if ($num > 5) {
 | |
|                 throw new \think\Exception('其他资质图片不能超过五张', 10006);
 | |
|             }
 | |
| 
 | |
|             Shop::update([
 | |
|                 'nickname'       => $post['nickname'],
 | |
|                 'mobile'         => $post['mobile'],
 | |
|                 'keywords'       => $post['keywords'] ?? '',
 | |
|                 'intro'          => $post['intro'] ?? '',
 | |
|                 'is_run'         => $post['is_run'],
 | |
| //                'service_mobile' => $post['service_mobile'],
 | |
|                 'weekdays'       => $post['weekdays'] ?? '',
 | |
|                 'province_id'    => $post['province_id'] ?? 0,
 | |
|                 'city_id'        => $post['city_id'] ?? 0,
 | |
|                 'district_id'    => $post['district_id'] ?? 0,
 | |
|                 'address'        => $post['address'] ?? '',
 | |
|                 'longitude'      => $post['longitude'] ?? '',
 | |
|                 'latitude'       => $post['latitude'] ?? '',
 | |
|                 'run_start_time' => empty($post['run_start_time']) ? '' : strtotime($post['run_start_time']),
 | |
|                 'run_end_time'   => empty($post['run_end_time']) ? '' : strtotime($post['run_end_time']),
 | |
|                 'refund_address' => json_encode([
 | |
|                     'nickname'    => $post['refund_nickname'],
 | |
|                     'mobile'      => $post['refund_mobile'],
 | |
|                     'province_id' => $post['refund_province_id'],
 | |
|                     'city_id'     => $post['refund_city_id'],
 | |
|                     'district_id' => $post['refund_district_id'],
 | |
|                     'address'     => $post['refund_address'],
 | |
|                 ], JSON_UNESCAPED_UNICODE),
 | |
|                 'business_license'   => empty($post['business_license']) ? '' : UrlServer::setFileUrl($post['business_license']),
 | |
|                 'other_qualifications' => isset($post['other_qualifications']) ? json_encode($post['other_qualifications'], JSON_UNESCAPED_UNICODE) : '',
 | |
|                 'open_invoice'  => $post['open_invoice'] ?? 0,
 | |
|                 'spec_invoice'     => $post['spec_invoice'] ?? 0,
 | |
|             ], ['id'=>$post['id']]);
 | |
| 
 | |
|             return true;
 | |
|         } catch (\Exception $e) {
 | |
|             static::$error = $e->getMessage();
 | |
|             return false;
 | |
|         }
 | |
|     }
 | |
| } |