| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?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\adminapi\logic\agricultural_machinery;
- use app\common\enum\PayEnum;
- use app\common\enum\YesNoEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\agricultural_machinery\UserService;
- use app\common\model\article\ArticleCate;
- use app\common\model\user\User;
- use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
- use app\common\model\recharge\RechargeOrder;
- use app\common\model\ServiceCharge;
- use think\facade\Db;
- /**
- * 服务管理逻辑
- * Class ArticleCateLogic
- * @package app\adminapi\logic\article
- */
- class UserServiceLogic extends BaseLogic
- {
- /**
- * @notes 添加农耕分类
- * @param array $params
- * @author heshihu
- * @date 2022/2/18 10:17
- */
- public static function add(array $params,$type_name)
- {
- Db::startTrans();
- try {
- $where['user_id'] = $params['user_id'];
- $where['type'] = $params['type'];
- $userService = UserService::where($where)->findOrEmpty();
- if(!$userService->isEmpty()){
- Db::rollback();
- self::setError('当前用户存在'.$type_name.'服务信息,无需添加');
- return ['code'=>0,'data'=>[]];
- }
- $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'],
- 'cate_id' => ','.$params['cate_id'].',',
- 'area_id' => ','.$params['area_id'].',',
- 'money' => $params['money'],
- 'content'=>$params['content'],
- 'order_id'=>0,
- ]);
- if($result){
- $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'],
- 'pay_way'=> 4,
- 'pay_time'=>time(),
- 'service_id'=>$result['id'],
- 'pay_status' => PayEnum::ISPAID,
- '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->status = 1;
- $user_service_info->expiration_time = time()+365*24*60*60;
- $user_service_info->save();
- $order_info = [
- 'order_id' => (int)$order['id'],
- 'order_sn' => $order['sn'],
- '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 array $params
- * @author heshihu
- * @date 2022/2/21 17:52
- */
- public static function delete(array $params)
- {
- UserService::destroy($params['id']);
- }
- /**
- * @notes 查看服务商详情
- * @param $params
- * @return array
- * @author heshihu
- * @date 2022/2/21 17:54
- */
- public static function detail($params) : array
- {
- return UserService::findOrEmpty($params['id'])->toArray();
- }
- /**
- * @notes 更改服务商状态
- * @param array $params
- * @return bool
- * @author heshihu
- * @date 2022/2/21 18:04
- */
- public static function updateStatus(array $params)
- {
- UserService::update([
- 'id' => $params['id'],
- 'status' => $params['status']
- ]);
- return true;
- }
- /**
- * @notes 有效用户数据
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author 段誉
- * @date 2022/10/13 10:53
- */
- public static function getValidUserData()
- {
- $list = User::where(['is_disable' => YesNoEnum::NO])
- ->field('id,sn,nickname,account')
- ->order([ 'id' => 'desc'])
- ->select()
- ->toArray();
- return $list;
- }
- public static function getServiceContent(){
- $info = ServiceCharge::field('agricultural_service,bake_service,air_service')->find(1)->toArray();
- return $info;
- }
- public static function saveServiceContent($post){
- if(isset($post['agricultural_service']) && !empty($post['agricultural_service'])){
- $saveData['agricultural_service'] = $post['agricultural_service'];
- }
- if(isset($post['bake_service']) && !empty($post['bake_service'])){
- $saveData['bake_service'] = $post['bake_service'];
- }
- if(isset($post['air_service']) && !empty($post['air_service'])){
- $saveData['air_service'] = $post['air_service'];
- }
- $saveData['id'] = 1;
- ServiceCharge::update($saveData);
- return true;
- }
- }
|