| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\api\logic;
- use app\common\logic\BaseLogic;
- use app\common\enum\{LoginEnum, PayEnum};
- use app\common\service\{
- ConfigService,
- };
- use app\common\model\agricultural_machinery\UserService;
- use app\common\model\agricultural_machinery\ServiceCategory;
- use app\common\model\agricultural_machinery\ServiceScanLog;
- use app\common\model\agricultural_machinery\MechanicalCate;
- use app\common\model\ServiceCharge;
- use app\common\model\asset\AssetArea;
- use app\common\model\recharge\RechargeOrder;
- use app\common\model\user\{User, UserAuth};
- use think\facade\{Db, Config};
- /**
- * 服务商逻辑
- * Class LoginLogic
- * @package app\api\logic
- */
- class ServiceLogic extends BaseLogic
- {
- /**
- * @notes 入驻
- * @param array $params
- * @return bool
- * @author 段誉
- * @date 2022/9/7 15:37
- */
- public static function Settled(array $params)
- {
- Db::startTrans();
- try {
- $service_fee = ServiceCharge::find(1);
- $order_money = 0;
- $flag = false ;
- switch ($params['type']){
- case 1 :
- $flag = true ;
- $order_money =$service_fee['agricultural_machinery_service_fee'];
- break;
- case 2 :
- $flag = true ;
- $order_money =$service_fee['bake_service_fee'];
- break;
- case 3 :
- $flag = true ;
- $order_money =$service_fee['air_control_service_fee'];
- break;
- }
- $result = UserService::create([
- 'user_id' => $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;
- }
- }
- }
|