$params['user_id'], 'type' => $params['type'] ?? 1, 'name' => $params['name'], 'mobile' => $params['mobile'], 'agricultural_machinery_model' =>$params['agricultural_machinery_model'], 'images' => $params['images']??'', 'driving_image' => $params['driving_image']??'', 'driver_image' => $params['driver_image']??'', 'agricultural_image' => $params['agricultural_image']??'', 'cate_id' => ','.$params['cate_id'].',', 'area_id' => ','.$params['area_id'].',', 'mechanical_cate_id' => ','.$params['mechanical_cate_id'].',', 'money' => $params['money'], 'content'=>$params['content']??'', 'order_id'=>0, ]); if($result){ $data = [ 'sn' => generate_sn(RechargeOrder::class, 'sn'), 'user_id' => $params['user_id'], 'service_id'=>$result['id'], 'pay_status' => PayEnum::UNPAID, 'order_amount' => $order_money, ]; $order = RechargeOrder::create($data); $user_service_info = UserService::find($result['id']); $user_service_info->order_id = $order['id']; $user_service_info->save(); if($flag){ switch ($params['type']){ case 1 : $updateData['agricultural_id'] =(int)$order['id']; $updateData['agricultural_status'] =1; break; case 2 : $updateData['bake_id'] =(int)$order['id']; $updateData['bake_status'] =1; break; case 3 : $updateData['air_id'] =(int)$order['id']; $updateData['air_status'] =1; break; } $updateData['id'] = $params['user_id']; User::update($updateData); } $order_info = [ 'order_id' => (int)$order['id'], 'order_sn' => $order['sn'], 'order_money'=>$order_money, 'from' => 'service', 'result'=>$result ]; } Db::commit(); return ['code'=>1,'data'=>$order_info]; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return ['code'=>0,'data'=>[]]; } } /** * @notes * @param $params * @return array|false * @author 段誉 * @date 2022/9/6 19:26 */ public static function getInfo($params,$user_id) { try { $where = []; $where[]=['user_id','=',$user_id]; $where[]=['type','=',$params['type']]; $serviceInfo = UserService::where($where)->append(['type_desc','cate_desc','area_desc','images','user','orderInfo'])->findOrEmpty(); if($serviceInfo->isEmpty()){ $status = -1; }else{ if($serviceInfo['status'] == 0){ $status = 0; }else if($serviceInfo['status'] == 2){ $status = 2; }else{ $status = 1; } } return [ 'status' => $status, 'info' => $serviceInfo, ]; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } /** * @notes 地址列表 * @author 段誉 * @date 2022/9/16 17:56 */ public static function getsAreaLists($get) { $where=[]; $where[]=['status','=',1]; if(isset($get['title'])){ $where[]=['title','like','%'.$get['title'].'%']; } $area_list = AssetArea::where($where)->field('id,id value,level,pid,title,title label')->order('sort desc,id asc')->select()->toArray(); if($get['is_tree'] ==1){ $treeList = linear_to_tree($area_list, 'children'); if (empty($treeList) && !empty($area_list)) { foreach ($area_list as &$v) { $v['children'] = []; } return $area_list; } return $treeList; }else{ return $area_list; } } /** * @notes 地址列表 * @author 段誉 * @date 2022/9/16 17:56 */ public static function getsCateLists($get) { $where=[]; $where[]=['type','=',$get['type']]; $where[]=['status','=',1]; if(isset($get['name'])){ $where[]=['name','like','%'.$get['name'].'%']; } $cate_list = ServiceCategory::where($where)->field('id,name')->order('sort desc,id asc')->select()->toArray(); return $cate_list; } public static function getsMechanicalCateLists($get){ $where=[]; if(isset($get['name'])){ $where[]=['name','like','%'.$get['name'].'%']; } $where[]=['type','=',$get['type']]; $cate_list = MechanicalCate::where($where)->field('id,name')->order('sort desc,id asc')->select()->toArray(); return $cate_list; } /** * @notes 续费订单 * @param array $params * @return bool * @author 段誉 * @date 2022/9/7 15:37 */ public static function Renew(array $params) { Db::startTrans(); try { $where['user_id'] = $params['user_id']; $where['type'] = $params['type']; $info = UserService::where($where)->findOrEmpty(); $order_info = []; if($info){ if($info['expiration_time'] > time()){ Db::rollback(); self::setError('服务未到期,无需进行续费操作'); return ['code'=>0,'data'=>[]]; } $service_fee = ServiceCharge::find(1); $order_money = 0; switch ($params['type']){ case 1 : $order_money =$service_fee['agricultural_machinery_service_fee']; break; case 2 : $order_money =$service_fee['bake_service_fee']; break; case 3 : $order_money =$service_fee['air_control_service_fee']; break; } $data = [ 'sn' => generate_sn(RechargeOrder::class, 'sn'), 'user_id' => $params['user_id'], 'service_id'=>$info['id'], 'pay_status' => PayEnum::UNPAID, 'order_amount' => $order_money, ]; $order = RechargeOrder::create($data); $info->order_id = $order['id']; $info->status = 0; $info->save(); $order_info = [ 'order_id' => (int)$order['id'], 'order_sn' => $order['sn'], 'from' => 'service', ]; } Db::commit(); return ['code'=>1,'data'=>$order_info]; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return ['code'=>0,'data'=>[]]; } } public static function updateServiceStatus(){ $where = []; $where[]=['status','=' ,1]; $where[]=['is_auto_upd','=', 0]; $where[]=['expiration_time','<', time()]; $list = UserService::where($where)->select()->toArray(); $remark = ''; foreach($list as $k=>$v){ $updatewhere['id'] = $v['id']; $updateData['status'] = 2; $updateData['is_auto_upd'] = 1; UserService::where($updatewhere)->update($updateData); $remark .='id='.$v['id'].'~已到期,状态更新~'; } if(empty($remark)){ $remark = '无更新数据'; } return $remark; } public static function getServiceContentInfo(){ $where['id'] = 1; $info = ServiceCharge::field('agricultural_service,bake_service,air_service')->find(1)->toArray(); return $info; } public static function getUserServiceInfo($user_id){ $info = User::field('id,nickname,mobile,agricultural_status,agricultural_id,bake_status,bake_id,air_status,air_id') ->with(['agricultural','bake','air'])->find($user_id)->toArray(); return $info; } public static function getServiceDisclaimer(){ $data['disclaimer'] = ConfigService::get('website', 'disclaimer'); return $data; } /** * @notes 插入浏览日志 * @param array $params * @return bool * @author 段誉 * @date 2022/9/7 15:37 */ public static function addLog(array $params) { try { $data = [ 'sn' => generate_sn(RechargeOrder::class, 'sn'), 'user_id' => $params['user_id'], 'type' => $params['log_type'], 'service_user_id' => $params['service_user_id']??0, ]; ServiceScanLog::create($data); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } }