|
|
@@ -0,0 +1,928 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 版权所有 2017~2021 LARAVEL研发中心
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 官方网站: http://www.laravel.cn
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: laravel开发员 <laravel.qq.com>
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+
|
|
|
+namespace App\Services\Api;
|
|
|
+
|
|
|
+use App\Models\AccountLogModel;
|
|
|
+use App\Models\MerchantCategoryModel;
|
|
|
+use App\Models\MerchantModel;
|
|
|
+use App\Services\BaseService;
|
|
|
+use App\Services\ConfigService;
|
|
|
+use App\Services\RedisService;
|
|
|
+use App\Services\SmsService;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商户服务管理-服务类
|
|
|
+ * @author laravel开发员
|
|
|
+ * @since 2020/11/11
|
|
|
+ * Class MerchantService
|
|
|
+ * @package App\Services\Api
|
|
|
+ */
|
|
|
+class MerchantService extends BaseService
|
|
|
+{
|
|
|
+ // 静态对象
|
|
|
+ protected static $instance = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ * @author laravel开发员
|
|
|
+ * @since 2020/11/11
|
|
|
+ * MerchantService constructor.
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->model = new MerchantModel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 静态入口
|
|
|
+ * @return static|null
|
|
|
+ */
|
|
|
+ public static function make()
|
|
|
+ {
|
|
|
+ if (!self::$instance) {
|
|
|
+ self::$instance = (new static());
|
|
|
+ }
|
|
|
+ return self::$instance;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取缓存列表
|
|
|
+ * @param $position
|
|
|
+ * @param int $num
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getDataList($params, $pageSize = 15, $refresh = false, $field = '')
|
|
|
+ {
|
|
|
+ $page = request()->post('page', 1);
|
|
|
+ $cacheKey = "caches:merchant:page_{$page}_" . md5(json_encode($params).$pageSize);
|
|
|
+ $datas = RedisService::get($cacheKey);
|
|
|
+ $data = isset($datas['data'])? $datas['data'] : [];
|
|
|
+ if ($datas && $data && !$refresh) {
|
|
|
+ return [
|
|
|
+ 'list'=> $data,
|
|
|
+ 'total'=> isset($datas['total'])? $datas['total'] : 0,
|
|
|
+ 'pageSize'=>$pageSize
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $field = $field ? $field : 'lev_a.id,lev_a.user_id,lev_a.name,lev_a.logo,lev_a.type,lev_a.category,lev_a.business_scope,lev_a.service_time,lev_a.deposit,lev_a.service_order_num,lev_a.score_rate,lev_a.city,lev_a.lng,lev_a.lat,lev_a.status';
|
|
|
+ $lat = isset($params['lat']) ? $params['lat'] : 0.00;
|
|
|
+ $lng = isset($params['lng']) ? $params['lng'] : 0.00;
|
|
|
+ $sortType = isset($params['sort_type']) ? $params['sort_type'] : 0;
|
|
|
+ $order = 'lev_a.id desc';
|
|
|
+
|
|
|
+ $datas = $this->model->from('merchant as a')
|
|
|
+ ->leftJoin('member as b','b.id','=','a.user_id')
|
|
|
+ ->where(['a.mark' => 1,'b.mark'=>1])
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
+ $kw = isset($params['kw']) ? trim($params['kw']) : '';
|
|
|
+ if ($kw) {
|
|
|
+ $query->where('a.name', 'like', "%{$kw}%")->orWhere('a.business_scope', 'like', "%{$kw}%");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
+ // 商户类型
|
|
|
+ $type = isset($params['type']) ? intval($params['type']) : 0;
|
|
|
+ if ($type) {
|
|
|
+ $query->where('a.type', $type);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 状态
|
|
|
+ $status = isset($params['status']) && $params['status']>=0 ? intval($params['status']) : 2;
|
|
|
+ if ($status>0) {
|
|
|
+ $query->where('a.status', $status);
|
|
|
+ }else{
|
|
|
+ $query->whereIn('a.status',[1,2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 经营类目
|
|
|
+ $category = isset($params['category']) ? intval($params['category']) : 0;
|
|
|
+ if ($category) {
|
|
|
+ $query->where('a.category', $category);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 省
|
|
|
+ $province = isset($params['province']) ? trim($params['province']) : '';
|
|
|
+ $city = isset($params['city']) ? trim($params['city']) : '';
|
|
|
+ if ($province && empty($city)) {
|
|
|
+ $query->where('a.province', 'like',"{$province}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 市
|
|
|
+ if ($city) {
|
|
|
+ $query->where(function($query) use($city){
|
|
|
+ $query->where('a.city', $city)->orWhere('a.address','like',"%{$city}%");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否保障金
|
|
|
+ $isDeposit = isset($params['deposit']) ? intval($params['deposit']) : 0;
|
|
|
+ if ($isDeposit) {
|
|
|
+ $query->where('a.deposit', '>', 0);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->selectRaw($field)
|
|
|
+ ->orderByRaw($order)
|
|
|
+ ->paginate($pageSize > 0 ? $pageSize : 9999999);
|
|
|
+
|
|
|
+ $datas = $datas ? $datas->toArray() : [];
|
|
|
+ if ($datas) {
|
|
|
+ foreach($datas['data'] as &$item){
|
|
|
+ $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
|
|
|
+ $item['score_rate'] = max(0, moneyFormat($item['score_rate'], 1));
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ RedisService::set($cacheKey, $datas, rand(3, 5));
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'list'=> isset($datas['data'])? $datas['data'] : [],
|
|
|
+ 'total'=> isset($datas['total'])? $datas['total'] : 0,
|
|
|
+ 'pageSize'=>$pageSize
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取详情
|
|
|
+ * @param $id 商家ID
|
|
|
+ * @param string $type
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getInfoById($id, $type='info', $userId=0)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:merch:{$type}_{$id}";
|
|
|
+ $info = RedisService::get($cacheKey);
|
|
|
+ if($info){
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+ $field = ['a.id','a.name','a.user_id','a.type','a.logo','a.category','a.business_scope','a.balance','a.usdt','a.service_time','a.deposit','a.delivery_fee','a.bonus_rate','a.power_rate','a.status','a.trade_status','b.username','b.nickname'];
|
|
|
+ $info = $this->model->from('merchant as a')->with(['category'])
|
|
|
+ ->leftJoin('member as b','b.id','=','a.user_id')
|
|
|
+ ->where(['a.id'=> $id,'a.mark'=>1,'b.mark'=>1])
|
|
|
+ ->select($field)
|
|
|
+ ->first();
|
|
|
+ $info = $info? $info->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ if(isset($info['logo'])){
|
|
|
+ $info['logo'] = $info['logo']? get_image_url($info['logo']) : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($info['albums'])){
|
|
|
+ $info['albums'] = $info['albums']? json_decode($info['albums'], true) : [];
|
|
|
+ $info['albums'] = $info['albums']? get_images_preview($info['albums']) : [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['service_status'] = 2;
|
|
|
+ $info['service_time'] = isset($info['service_time']) && $info['service_time']? $info['service_time']:'08点~22点';
|
|
|
+ $serviceTime = $info['service_time']? str_replace('~','~',$info['service_time']):'';
|
|
|
+ $times = $serviceTime? explode('~',$serviceTime) : [];
|
|
|
+ $times[0] = isset($times[0]) && $times[0]? $times[0] : '08点';
|
|
|
+ $times[1] = isset($times[1]) && $times[1]? $times[1] : '22点';
|
|
|
+ if($times && date('H点')>= $times[0] && date('H点')<=$times[1]){
|
|
|
+ $info['service_status'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($info['trade_status'] != 1){
|
|
|
+ $info['service_status'] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ RedisService::set($cacheKey, $info, rand(3, 5));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加或编辑
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author laravel开发员
|
|
|
+ */
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ $data = request()->all();
|
|
|
+ // 图片处理
|
|
|
+ $cover = $data['cover'] ? trim($data['cover']) : '';
|
|
|
+ if (strpos($cover, "temp")) {
|
|
|
+ $data['cover'] = save_image($cover, 'ad');
|
|
|
+ } else {
|
|
|
+ $data['cover'] = str_replace(IMG_URL, "", $data['cover']);
|
|
|
+ }
|
|
|
+ // 开始时间
|
|
|
+ if (isset($data['start_time'])) {
|
|
|
+ $data['start_time'] = strtotime($data['start_time']);
|
|
|
+ }
|
|
|
+ // 结束时间
|
|
|
+ if (isset($data['end_time'])) {
|
|
|
+ $data['end_time'] = strtotime($data['end_time']);
|
|
|
+ }
|
|
|
+ return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改信息
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return array|false|int[]
|
|
|
+ */
|
|
|
+ public function saveInfo($userId, $params)
|
|
|
+ {
|
|
|
+ // 验证是否入驻过和入驻状态
|
|
|
+ $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ $mark = isset($info['mark'])? $info['mark'] : 0;
|
|
|
+ $merchId = isset($info['id'])? $info['id'] : 0;
|
|
|
+ if($merchId && empty($info)){
|
|
|
+ $this->error = 2216;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否被冻结
|
|
|
+ if($merchId && $status == 3 && $mark){
|
|
|
+ $this->error = 2202;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否是技师
|
|
|
+ if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
|
|
|
+ $this->error = 2687;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证账户是否正常
|
|
|
+ $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
|
|
|
+ $status = isset($userInfo['status'])? $userInfo['status'] : 0;
|
|
|
+ if(empty($userInfo) || $status != 1){
|
|
|
+ $this->error = 2017;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = isset($params['type'])? intval($params['type']) : 0;
|
|
|
+ $category = isset($params['category'])? intval($params['category']) : 0;
|
|
|
+ $lng = isset($params['lng'])? floatval($params['lng']) : 0;
|
|
|
+ $lat = isset($params['lat'])? floatval($params['lat']) : 0;
|
|
|
+ $address = isset($params['address'])? trim($params['address']) : '';
|
|
|
+ $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
|
|
|
+ $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
|
|
|
+ $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
|
|
|
+ $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
|
|
|
+ $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
|
|
|
+ $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
|
|
|
+ $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
|
|
|
+ $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
|
|
|
+ $logoData = isset($params['logo'])? $params['logo'] : [];
|
|
|
+ $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
|
|
|
+ $name = isset($params['name'])? $params['name'] : '';
|
|
|
+
|
|
|
+ // 验证分类
|
|
|
+ if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
|
|
|
+ $this->error = 2203;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证logo
|
|
|
+ if(empty($logo)){
|
|
|
+ $this->error = 2204;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 位置信息
|
|
|
+ if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
|
|
|
+ $this->error = 2210;
|
|
|
+ //return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 证书
|
|
|
+ if(empty($file1)){
|
|
|
+ $this->error = $type == 1? 2206 : 2211;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($file2)){
|
|
|
+ $this->error = 2207;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($file3)){
|
|
|
+ $this->error = $type==1? 2208 : 2209;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收款码
|
|
|
+ if(empty($alipayQrcode) || empty($wxpayQrcode)){
|
|
|
+ $this->error = 2205;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 入驻数据
|
|
|
+ $data = [
|
|
|
+ 'name' => $name,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'category'=> $category,
|
|
|
+ 'type'=> $type,
|
|
|
+ 'logo'=> $logo,
|
|
|
+ 'albums'=> $albums? $albums : '',
|
|
|
+ 'qualification_imgs'=> $file1? $file1 : '',
|
|
|
+ 'other_certificates'=> $file2? $file2 : '',
|
|
|
+ 'idcard_imgs'=> $file3? $file3 : '',
|
|
|
+ 'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
|
|
|
+ 'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
|
|
|
+ 'lng'=> $lng,
|
|
|
+ 'lat'=> $lat,
|
|
|
+ 'address'=> $address,
|
|
|
+ 'province'=> isset($params['province'])? trim($params['province']) : '',
|
|
|
+ 'city'=> isset($params['city'])? trim($params['city']) : '',
|
|
|
+ 'district'=> isset($params['district'])? trim($params['district']) : '',
|
|
|
+ 'intro'=> isset($params['intro'])? trim($params['intro']) : '',
|
|
|
+ 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
|
|
|
+ 'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
|
|
|
+ 'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 写入数据
|
|
|
+ if($merchId){
|
|
|
+ if($this->model->where(['id'=> $merchId])->update($data)){
|
|
|
+ $this->error = 2228;
|
|
|
+ RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
|
|
|
+ return ['id'=> $merchId];
|
|
|
+ }else{
|
|
|
+ $this->error = 2229;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if($merchId = $this->model->insertGetId($data)){
|
|
|
+ $this->error = 2228;
|
|
|
+ RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
|
|
|
+ return ['id'=> $merchId];
|
|
|
+ }else{
|
|
|
+ $this->error = 2229;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 申请入驻
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return array|false|int[]
|
|
|
+ */
|
|
|
+ public function apply($userId, $params)
|
|
|
+ {
|
|
|
+ // 验证是否入驻过和入驻状态
|
|
|
+ $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ $mark = isset($info['mark'])? $info['mark'] : 0;
|
|
|
+ $merchId = isset($info['id'])? $info['id'] : 0;
|
|
|
+ if($merchId && $status == 2 && $mark){
|
|
|
+ $this->error = 2201;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否被冻结
|
|
|
+ if($merchId && $status == 3 && $mark){
|
|
|
+ $this->error = 2202;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否是技师
|
|
|
+ if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
|
|
|
+ $this->error = 2687;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证账户是否正常
|
|
|
+ $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
|
|
|
+ $status = isset($userInfo['status'])? $userInfo['status'] : 0;
|
|
|
+ if(empty($userInfo) || $status != 1){
|
|
|
+ $this->error = 2017;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = isset($params['type'])? intval($params['type']) : 0;
|
|
|
+ $category = isset($params['category'])? intval($params['category']) : 0;
|
|
|
+ $lng = isset($params['lng'])? floatval($params['lng']) : 0;
|
|
|
+ $lat = isset($params['lat'])? floatval($params['lat']) : 0;
|
|
|
+ $address = isset($params['address'])? trim($params['address']) : '';
|
|
|
+ $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
|
|
|
+ $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
|
|
|
+ $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
|
|
|
+ $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
|
|
|
+ $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
|
|
|
+ $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
|
|
|
+ $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
|
|
|
+ $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
|
|
|
+ $logoData = isset($params['logo'])? $params['logo'] : [];
|
|
|
+ $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
|
|
|
+ $name = isset($params['name'])? $params['name'] : '';
|
|
|
+
|
|
|
+ // 验证分类
|
|
|
+ if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
|
|
|
+ $this->error = 2203;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证logo
|
|
|
+ if(empty($logo)){
|
|
|
+ $this->error = 2204;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 位置信息
|
|
|
+ if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
|
|
|
+ $this->error = 2210;
|
|
|
+ //return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 证书
|
|
|
+ if(empty($file1)){
|
|
|
+ $this->error = $type == 1? 2206 : 2211;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($file2)){
|
|
|
+ $this->error = 2207;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($file3)){
|
|
|
+ $this->error = $type==1? 2208 : 2209;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收款码
|
|
|
+ if(empty($alipayQrcode) || empty($wxpayQrcode)){
|
|
|
+ $this->error = 2205;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 入驻数据
|
|
|
+ $data = [
|
|
|
+ 'name' => $name,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'category'=> $category,
|
|
|
+ 'type'=> $type,
|
|
|
+ 'logo'=> $logo,
|
|
|
+ 'albums'=> $albums? $albums : '',
|
|
|
+ 'qualification_imgs'=> $file1? $file1 : '',
|
|
|
+ 'other_certificates'=> $file2? $file2 : '',
|
|
|
+ 'idcard_imgs'=> $file3? $file3 : '',
|
|
|
+ 'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
|
|
|
+ 'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
|
|
|
+ 'lng'=> $lng,
|
|
|
+ 'lat'=> $lat,
|
|
|
+ 'address'=> $address,
|
|
|
+ 'province'=> isset($params['province'])? trim($params['province']) : '',
|
|
|
+ 'city'=> isset($params['city'])? trim($params['city']) : '',
|
|
|
+ 'district'=> isset($params['district'])? trim($params['district']) : '',
|
|
|
+ 'intro'=> isset($params['intro'])? trim($params['intro']) : '',
|
|
|
+ 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
|
|
|
+ 'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
|
|
|
+ 'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 写入数据
|
|
|
+ if($merchId){
|
|
|
+ if($this->model->where(['id'=> $merchId])->update($data)){
|
|
|
+ $this->error = 2213;
|
|
|
+ return ['id'=> $merchId];
|
|
|
+ }else{
|
|
|
+ $this->error = 2214;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if($merchId = $this->model->insertGetId($data)){
|
|
|
+ $this->error = 2215;
|
|
|
+ return ['id'=> $merchId];
|
|
|
+ }else{
|
|
|
+ $this->error = 2214;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取商家入驻信息
|
|
|
+ * @param $userId
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getApplyInfo($userId)
|
|
|
+ {
|
|
|
+ $info = $this->model->with(['category'])->where(['user_id'=> $userId,'mark'=>1])
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->first();
|
|
|
+ $info = $info? $info->setHidden(['balance','deposit','update_time','mark'])->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ $info['logo'] = isset($info['logo']) && $info['logo']? [['url'=> get_image_url($info['logo'])]] : [];
|
|
|
+ $info['alipay_qrcode'] = isset($info['alipay_qrcode']) && $info['alipay_qrcode']? [['url'=> get_image_url($info['alipay_qrcode'])]] : [];
|
|
|
+ $info['wxpay_qrcode'] = isset($info['wxpay_qrcode']) && $info['wxpay_qrcode']? [['url'=> get_image_url($info['wxpay_qrcode'])]] : [];
|
|
|
+ $file1 = isset($info['qualification_imgs']) && $info['qualification_imgs']? json_decode($info['qualification_imgs'], true) : [];
|
|
|
+ $info['file1'] = $file1? get_images_preview($file1) : [];
|
|
|
+ $file2 = isset($info['other_certificates']) && $info['other_certificates']? json_decode($info['other_certificates'], true) : [];
|
|
|
+ $info['file2'] = $file2? get_images_preview($file2) : [];
|
|
|
+ $file3 = isset($info['idcard_imgs']) && $info['idcard_imgs']? json_decode($info['idcard_imgs'], true) : [];
|
|
|
+ $info['file3'] = $file3? get_images_preview($file3) : [];
|
|
|
+ $albums = isset($info['albums']) && $info['albums']? json_decode($info['albums'], true) : [];
|
|
|
+ $info['albums'] = $albums? get_images_preview($albums) : [];
|
|
|
+ if(isset($info['category']) && $info['category']){
|
|
|
+ $info['category_name'] = isset($info['category']['name'])? $info['category']['name'] : '';
|
|
|
+ $info['category'] = isset($info['category']['id'])? $info['category']['id'] : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($info['qualification_imgs']);
|
|
|
+ unset($info['other_certificates']);
|
|
|
+ unset($info['idcard_imgs']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function applyConfirm($userId, $params)
|
|
|
+ {
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ if(empty($info) || $id<=0){
|
|
|
+ $this->error = 2230;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($status != 1){
|
|
|
+ $this->error = 2231;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = isset($params['status'])? intval($params['status']) : 0;
|
|
|
+ $auditRemark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
|
|
|
+ if(!in_array($status,[2,3])){
|
|
|
+ $this->error = 2232;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->model->where(['id'=> $id])->update(['status'=> $status,'audit_remark'=>$auditRemark,'update_time'=>time()])){
|
|
|
+ $this->error = 1040;
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ $this->error = 1041;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function lock($userId, $params)
|
|
|
+ {
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ if(empty($info) || $id<=0){
|
|
|
+ $this->error = 2230;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($status <= 1){
|
|
|
+ $this->error = 2234;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $agentInfo = AgentModel::where(['user_id'=> $userId,'mark'=>1])->select(['id','user_id','realname'])->first();
|
|
|
+ $agentId = isset($agentInfo['id'])? $agentInfo['id'] : 0;
|
|
|
+ if(empty($agentInfo)){
|
|
|
+ $this->error = 2024;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = isset($params['status'])? intval($params['status']) : 0;
|
|
|
+ $remark = isset($params['remark'])? trim($params['remark']) : '';
|
|
|
+ if(!in_array($status,[2,3])){
|
|
|
+ $this->error = 2232;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->model->where(['id'=> $id])->update(['agent_lock'=>1,'agent_lock_id'=> $agentId,'agent_lock_status'=> $status,'agent_lock_remark'=>$remark,'update_time'=>time()])){
|
|
|
+ $this->error = 1035;
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ $this->error = 1036;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public function delete()
|
|
|
+ {
|
|
|
+ // 参数
|
|
|
+ $id = request()->post('id');
|
|
|
+ if (empty($id)) {
|
|
|
+ $this->error = 2014;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = 1002;
|
|
|
+ $this->model->where(['id'=> $id,'mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
|
|
|
+ return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function modify($userId, $params)
|
|
|
+ {
|
|
|
+ // 用户验证
|
|
|
+ $info = $this->model->where(['user_id' => $userId, 'mark' => 1])
|
|
|
+ ->select(['id','user_id', 'status'])
|
|
|
+ ->first();
|
|
|
+ if (!$info) {
|
|
|
+ $this->error = 2001;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用状态校验
|
|
|
+ if ($info['status'] != 2) {
|
|
|
+ $this->error = 2015;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码校验
|
|
|
+ $data = ['update_time' => time()];
|
|
|
+ $payPassword = isset($params['pay_password']) ? $params['pay_password'] : '';
|
|
|
+
|
|
|
+ // 手机号验证
|
|
|
+ $oldMobile = isset($params['old_mobile']) ? $params['old_mobile'] : '';
|
|
|
+ if (isset($params['old_mobile']) && $oldMobile) {
|
|
|
+ // 短信验证码
|
|
|
+ $code = isset($params['old_code']) ? $params['old_code'] : '';
|
|
|
+ if (empty($code)) {
|
|
|
+ $this->error = 2013;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!SmsService::make()->check($oldMobile, $code, 'modify')) {
|
|
|
+ $this->error = 1044;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 手机号验证
|
|
|
+ $mobile = isset($params['mobile']) ? $params['mobile'] : '';
|
|
|
+ if (isset($params['mobile']) && $mobile) {
|
|
|
+ $data['mobile'] = $mobile;
|
|
|
+ $checkInfo = $this->model->where(['mobile' => $mobile, 'mark' => 1])->select(['id','user_id', 'status'])->first();
|
|
|
+ if ($checkInfo && $checkInfo['user_id'] != $userId) {
|
|
|
+// $this->error = 2009;
|
|
|
+// return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 短信验证码
|
|
|
+ $code = isset($params['sms_code']) ? $params['sms_code'] : '';
|
|
|
+ if (empty($code)) {
|
|
|
+ $this->error = 2013;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!SmsService::make()->check($mobile, $code, 'modify')) {
|
|
|
+ $this->error = SmsService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($params['settle_type']) && in_array($params['settle_type'],[0,1,2,3])){
|
|
|
+ $data['settle_type'] = intval($params['settle_type']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($params['trade_status']) && in_array($params['trade_status'],[1,2])){
|
|
|
+ $data['trade_status'] = intval($params['trade_status']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($params['pay_password']) && $payPassword) {
|
|
|
+ $payPassword = get_password($payPassword);
|
|
|
+ $data['pay_password'] = $payPassword;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改数据
|
|
|
+ RedisService::clear("caches:merch:detail_{$info['id']}");
|
|
|
+ RedisService::keyDel("caches:merchant:info:temp*");
|
|
|
+ $this->model->where(['user_id' => $userId])->update($data);
|
|
|
+ $this->error = 1008;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 缴纳保证金
|
|
|
+ * @param $userId 商家用户
|
|
|
+ * @param $params
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public function deposit($userId, $params)
|
|
|
+ {
|
|
|
+ $merchId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $money = isset($params['money'])? $params['money'] : 0;
|
|
|
+ $payType = isset($params['pay_type']) && $params['pay_type']? intval($params['pay_type']) : 10;
|
|
|
+ if($money<=0){
|
|
|
+ $this->error = 2031;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!in_array($payType, [10,20])){
|
|
|
+ $this->error = 2032;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->model->where(['id'=> $merchId,'mark'=>1])
|
|
|
+ ->select(['id','name','mobile','balance','deposit','status'])
|
|
|
+ ->first();
|
|
|
+ $deposit = isset($info['deposit'])? $info['deposit'] : 0;
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ if($merchId<=0 || empty($info) || $status != 2){
|
|
|
+ $this->error = 2015;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 充值订单
|
|
|
+ $orderNo = get_order_num('DP');
|
|
|
+ $data = [
|
|
|
+ 'source_order_no'=> $orderNo,
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'merch_id'=> $merchId,
|
|
|
+ 'type'=> 14,
|
|
|
+ 'coin_type'=> 1,
|
|
|
+ 'user_type'=> 2,
|
|
|
+ 'money'=> $money,
|
|
|
+ 'balance'=> $deposit,
|
|
|
+ 'date'=> date('Y-m-d'),
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'remark'=> $payType == 10?'微信支付商家保证金':'支付宝支付商家保证金',
|
|
|
+ 'status'=> 2,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(!$orderId = AccountLogModel::insertGetId($data)){
|
|
|
+ $this->error = 2037;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付方式
|
|
|
+ $order = [
|
|
|
+ 'order_no'=> $orderNo,
|
|
|
+ 'type'=> 0,
|
|
|
+ 'pay_type'=> $payType,
|
|
|
+ 'pay_money'=> $money,
|
|
|
+ 'body'=> '缴纳保证金订单支付',
|
|
|
+ ];
|
|
|
+
|
|
|
+ switch($payType){
|
|
|
+ case 20: // 支付宝
|
|
|
+ $payment = PaymentService::make()->aliPay($info, $order,'deposit');
|
|
|
+ if(empty($payment)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = PaymentService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 10: // 微信支付
|
|
|
+ $payment = PaymentService::make()->wechatPay($info, $order,'deposit');
|
|
|
+ if(empty($payment)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = PaymentService::make()->getError();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $this->error = 1030;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = 2038;
|
|
|
+ return [
|
|
|
+ 'id'=> $orderId,
|
|
|
+ 'payment'=> $payment,
|
|
|
+ 'total'=> $money,
|
|
|
+ 'order_no'=> $orderNo,
|
|
|
+ 'pay_type'=> $payType,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退还保证金处理
|
|
|
+ * @param $userId 用户
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function rebackDeposit($userId, $params)
|
|
|
+ {
|
|
|
+ $merchId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ if($merchId<=0){
|
|
|
+ $this->error = 2039;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = $this->model->where(['id'=> $merchId,'mark'=>1])
|
|
|
+ ->select(['id','name','mobile','balance','deposit','status'])
|
|
|
+ ->first();
|
|
|
+ $deposit = isset($info['deposit'])? floatval($info['deposit']) : 0;
|
|
|
+ $balance = isset($info['balance'])? floatval($info['balance']) : 0;
|
|
|
+ $status = isset($info['status'])? $info['status'] : 0;
|
|
|
+ if($merchId<=0 || empty($info) || $status != 2){
|
|
|
+ $this->error = 2015;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($deposit<=0){
|
|
|
+ $this->error = 2041;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 时间限制
|
|
|
+ $depositTime = ConfigService::make()->getConfigByCode('shop_deposit_time');
|
|
|
+ $depositTime = $depositTime>=0? $depositTime : 0;
|
|
|
+ $paymentTime = AccountLogModel::where(['merch_id'=> $merchId,'type'=>14,'coin_type'=>1,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->value('create_time');
|
|
|
+ if($depositTime>0 && $paymentTime>0 && $paymentTime + ($depositTime*86400)> time()){
|
|
|
+ $this->error = lang(2040,['time'=> $depositTime]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ // 余额
|
|
|
+ $updateData = ['balance' => DB::raw("balance + {$deposit}"),'deposit'=>0.00, 'update_time' => time()];
|
|
|
+ if(!$this->model->where(['id'=> $merchId])->update($updateData)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = 2042;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 退还记录
|
|
|
+ $data = [
|
|
|
+ 'source_order_no'=> '',
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'merch_id'=> $merchId,
|
|
|
+ 'type'=> 14,
|
|
|
+ 'coin_type'=> 4,
|
|
|
+ 'user_type'=> 2,
|
|
|
+ 'money'=> -$deposit,
|
|
|
+ 'balance'=> $balance,
|
|
|
+ 'date'=> date('Y-m-d'),
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'remark'=> '商家保证金退还',
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(!$id = AccountLogModel::insertGetId($data)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = 2042;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ 'title' => '商家保证金退还到账通知',
|
|
|
+ 'body' => "您的商家保证金申请退还已成功,请点击查看详情",
|
|
|
+ 'type' => 3, // 1-公告通知,2-订单通知,3-交易通知,4-其他
|
|
|
+ 'content' => [
|
|
|
+ 'pay_time' => ['name' => '退还时间', 'text' => date('Y-m-d H:i:s')],
|
|
|
+ 'money' => ['name' => '金额', 'text' => $deposit],
|
|
|
+ 'balance' => ['name' => '当前余额', 'text' => moneyFormat($balance + $deposit,2)],
|
|
|
+ 'status' => ['name' => '状态', 'text' => '已到账'],
|
|
|
+ ],
|
|
|
+ 'click_type' => 'payload',
|
|
|
+ 'url' => '/pages/account/index?type=3',
|
|
|
+ ];
|
|
|
+
|
|
|
+ PushService::make()->pushMessageByUser($userId, $params, 0);
|
|
|
+ $this->error = 2043;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|