MerchantService.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\AccountLogModel;
  13. use App\Models\AgentModel;
  14. use App\Models\MechanicModel;
  15. use App\Models\MerchantCategoryModel;
  16. use App\Models\MerchantClerkModel;
  17. use App\Models\MerchantCollectModel;
  18. use App\Models\MerchantModel;
  19. use App\Services\BaseService;
  20. use App\Services\ConfigService;
  21. use App\Services\PushService;
  22. use App\Services\RedisService;
  23. use App\Services\SmsService;
  24. use Illuminate\Support\Facades\DB;
  25. /**
  26. * 商户服务管理-服务类
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * Class MerchantService
  30. * @package App\Services\Api
  31. */
  32. class MerchantService extends BaseService
  33. {
  34. // 静态对象
  35. protected static $instance = null;
  36. /**
  37. * 构造函数
  38. * @author laravel开发员
  39. * @since 2020/11/11
  40. * MerchantService constructor.
  41. */
  42. public function __construct()
  43. {
  44. $this->model = new MerchantModel();
  45. }
  46. /**
  47. * 静态入口
  48. * @return static|null
  49. */
  50. public static function make()
  51. {
  52. if (!self::$instance) {
  53. self::$instance = (new static());
  54. }
  55. return self::$instance;
  56. }
  57. /**
  58. * 获取缓存列表
  59. * @param $position
  60. * @param int $num
  61. * @return array|mixed
  62. */
  63. public function getDataList($params, $pageSize = 15, $refresh = false, $field = '')
  64. {
  65. $page = request()->post('page', 1);
  66. $cacheKey = "caches:merchant:page_{$page}_" . md5(json_encode($params).$pageSize);
  67. $datas = RedisService::get($cacheKey);
  68. $data = isset($datas['data'])? $datas['data'] : [];
  69. if ($datas && $data && !$refresh) {
  70. return [
  71. 'list'=> $data,
  72. 'total'=> isset($datas['total'])? $datas['total'] : 0,
  73. 'pageSize'=>$pageSize
  74. ];
  75. }
  76. $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';
  77. $lat = isset($params['lat']) ? $params['lat'] : 0.00;
  78. $lng = isset($params['lng']) ? $params['lng'] : 0.00;
  79. $sortType = isset($params['sort_type']) ? $params['sort_type'] : 0;
  80. $order = 'lev_a.id desc';
  81. if ($sortType == 1) { // 距离
  82. $order = 'distance asc, lev_a.id desc';
  83. } else if ($sortType == 2) { // 默认
  84. $order = 'lev_a.create_time desc, lev_a.id desc';
  85. } else if ($sortType == 3) { // 评分
  86. $order = 'lev_a.score_rate desc, lev_a.id desc';
  87. } else if ($sortType == 4) { // 人气销量
  88. $order = 'lev_a.service_order_num desc, lev_a.id desc';
  89. }
  90. $distanceField = '';
  91. if ($lat && $lng) {
  92. $distanceField = "ROUND(
  93. 6378.138 * 2 * ASIN(
  94. SQRT(
  95. POW(
  96. SIN(
  97. (
  98. {$lat} * PI() / 180 - lev_a.`lat` * PI() / 180
  99. ) / 2
  100. ),
  101. 2
  102. ) + COS({$lat} * PI() / 180) * COS(lev_a.`lat` * PI() / 180) * POW(
  103. SIN(
  104. (
  105. {$lng} * PI() / 180 - lev_a.`lng` * PI() / 180
  106. ) / 2
  107. ),
  108. 2
  109. )
  110. )
  111. ) * 1000
  112. )";
  113. $field .= ", {$distanceField} AS distance";
  114. }
  115. $distanceLimit = ConfigService::make()->getConfigByCode('distance_limit');
  116. $distanceLimit = $distanceLimit? $distanceLimit : 0;
  117. $datas = $this->model->from('merchant as a')
  118. ->leftJoin('member as b','b.id','=','a.user_id')
  119. ->where(['a.mark' => 1,'b.mark'=>1])
  120. ->where(function ($query) use ($params) {
  121. $kw = isset($params['kw']) ? trim($params['kw']) : '';
  122. if ($kw) {
  123. $query->where('a.name', 'like', "%{$kw}%")->orWhere('a.business_scope', 'like', "%{$kw}%");
  124. }
  125. })
  126. ->where(function ($query) use ($params,$distanceField,$distanceLimit) {
  127. // 商户类型
  128. $type = isset($params['type']) ? intval($params['type']) : 0;
  129. if ($type) {
  130. $query->where('a.type', $type);
  131. }
  132. // 状态
  133. $status = isset($params['status']) && $params['status']>=0 ? intval($params['status']) : 2;
  134. if ($status>0) {
  135. $query->where('a.status', $status);
  136. }else{
  137. $query->whereIn('a.status',[1,2]);
  138. }
  139. // 经营类目
  140. $category = isset($params['category']) ? intval($params['category']) : 0;
  141. if ($category) {
  142. $query->where('a.category', $category);
  143. }
  144. // 省
  145. $province = isset($params['province']) ? trim($params['province']) : '';
  146. $city = isset($params['city']) ? trim($params['city']) : '';
  147. if ($province && empty($city)) {
  148. $query->where('a.province', 'like',"{$province}%");
  149. }
  150. // 市
  151. if ($city) {
  152. $query->where(function($query) use($city){
  153. $query->where('a.city', $city)->orWhere('a.address','like',"%{$city}%");
  154. });
  155. }
  156. // 是否认证
  157. $isAuth = isset($params['is_auth']) ? intval($params['is_auth']) : 0;
  158. if ($isAuth) {
  159. $query->whereNotNull('a.idcard_imgs');
  160. }
  161. // 是否保障金
  162. $isDeposit = isset($params['deposit']) ? intval($params['deposit']) : 0;
  163. if ($isDeposit) {
  164. $query->where('a.deposit', '>', 0);
  165. }
  166. // 距离
  167. $lat = isset($params['lat']) ? $params['lat'] : 0.00;
  168. $lng = isset($params['lng']) ? $params['lng'] : 0.00;
  169. $distance = isset($params['distance']) ? intval($params['distance']) : 0;
  170. $distance = $distance? $distance*1000 : 0;
  171. $distanceLimit = $distance? $distance : $distanceLimit;
  172. if($lat>0 && $lng>0 && $distanceLimit>0 && $distanceField) {
  173. $query->whereRaw("{$distanceField} <= {$distanceLimit}");
  174. }
  175. })
  176. ->selectRaw($field)
  177. ->orderByRaw($order)
  178. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  179. $datas = $datas ? $datas->toArray() : [];
  180. if ($datas) {
  181. foreach($datas['data'] as &$item){
  182. $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
  183. $item['score_rate'] = max(0, moneyFormat($item['score_rate'], 1));
  184. if(isset($item['distance'])){
  185. $item['distance_text'] = $item['lat']>0 && $item['distance']>0? ($item['distance']<200? '200m以内':formatDistance($item['distance'])) : '';
  186. }
  187. }
  188. unset($item);
  189. RedisService::set($cacheKey, $datas, rand(3, 5));
  190. }
  191. return [
  192. 'list'=> isset($datas['data'])? $datas['data'] : [],
  193. 'total'=> isset($datas['total'])? $datas['total'] : 0,
  194. 'pageSize'=>$pageSize
  195. ];
  196. }
  197. /**
  198. * 获取缓存列表
  199. * @param $position
  200. * @param int $num
  201. * @return array|mixed
  202. */
  203. public function getRecommendList($params, $pageSize = 15, $refresh = false, $field = '')
  204. {
  205. $page = request()->post('page', 1);
  206. $cacheKey = "caches:merchant:page_{$page}_" . md5(json_encode($params).$pageSize);
  207. $datas = RedisService::get($cacheKey);
  208. if ($datas && !$refresh) {
  209. return $datas;
  210. }
  211. $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.city,lev_a.lng,lev_a.lat,lev_a.status';
  212. $lat = isset($params['lat']) ? $params['lat'] : 0.00;
  213. $lng = isset($params['lng']) ? $params['lng'] : 0.00;
  214. $sortType = isset($params['sort_type']) ? $params['sort_type'] : 0;
  215. $order = 'lev_a.id desc';
  216. if ($sortType == 1) {
  217. $order = 'distance desc, lev_a.id desc';
  218. } else if ($sortType == 2) {
  219. $order = 'lev_a.service_order_num desc, lev_a.id desc';
  220. }
  221. $distanceField = '';
  222. if ($lat>0 && $lng>0) {
  223. $distanceField = "ROUND(
  224. 6378.138 * 2 * ASIN(
  225. SQRT(
  226. POW(
  227. SIN(
  228. (
  229. {$lat} * PI() / 180 - lev_a.`lat` * PI() / 180
  230. ) / 2
  231. ),
  232. 2
  233. ) + COS({$lat} * PI() / 180) * COS(lev_a.`lat` * PI() / 180) * POW(
  234. SIN(
  235. (
  236. {$lng} * PI() / 180 - lev_a.`lng` * PI() / 180
  237. ) / 2
  238. ),
  239. 2
  240. )
  241. )
  242. ) * 1000
  243. )";
  244. $field .= ", {$distanceField} AS distance";
  245. }
  246. $distanceLimit = ConfigService::make()->getConfigByCode('distance_limit');
  247. $distanceLimit = $distanceLimit? $distanceLimit : 0;
  248. $datas = $this->model->from('merchant as a')
  249. ->leftJoin('member as b','b.id','=','a.user_id')
  250. ->where(['a.mark' => 1,'b.mark'=>1])
  251. ->where(function ($query) use ($params) {
  252. $kw = isset($params['kw']) ? trim($params['kw']) : '';
  253. if ($kw) {
  254. $query->where('a.name', 'like', "%{$kw}%")->orWhere('a.business_scope', 'like', "%{$kw}%");
  255. }
  256. })
  257. ->where(function ($query) use ($params,$distanceField,$distanceLimit) {
  258. // 商户类型
  259. $type = isset($params['type']) ? intval($params['type']) : 0;
  260. if ($type) {
  261. $query->where('a.type', $type);
  262. }
  263. // 状态
  264. $status = isset($params['status']) ? intval($params['status']) : 2;
  265. if ($status) {
  266. $query->where('a.status', $status);
  267. }
  268. // 经营类目
  269. $category = isset($params['category']) ? intval($params['category']) : 0;
  270. if ($category) {
  271. $query->where('a.category', $category);
  272. }
  273. // 省
  274. $province = isset($params['province']) ? trim($params['province']) : '';
  275. if ($province) {
  276. $query->where('a.province', $province);
  277. }
  278. // 市
  279. $city = isset($params['city']) ? trim($params['city']) : '';
  280. if ($city) {
  281. $query->where('a.city', $city);
  282. }
  283. // 是否认证
  284. $isAuth = isset($params['is_auth']) ? intval($params['is_auth']) : 0;
  285. if ($isAuth) {
  286. $query->whereNotNull('a.idcard_imgs');
  287. }
  288. // 是否保障金
  289. $isDeposit = isset($params['deposit']) ? intval($params['deposit']) : 0;
  290. if ($isDeposit) {
  291. $query->where('a.deposit', '>', 0);
  292. }
  293. $lat = isset($params['lat']) ? $params['lat'] : 0.00;
  294. $lng = isset($params['lng']) ? $params['lng'] : 0.00;
  295. if($lat>0 && $lng>0 && $distanceLimit>0 && $distanceField) {
  296. $query->whereRaw("{$distanceField} <= {$distanceLimit}");
  297. }
  298. })
  299. ->selectRaw($field)
  300. ->orderByRaw($order)
  301. ->paginate($pageSize > 0 ? $pageSize : 9999999)
  302. ->each(function($item,$k){
  303. $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
  304. if(isset($item['distance'])){
  305. $item['distance_text'] = $item['lat']>0? formatDistance($item['distance']) : '';
  306. }
  307. });
  308. $datas = $datas ? $datas->toArray() : [];
  309. if ($datas) {
  310. RedisService::set($cacheKey, $datas, rand(3, 5));
  311. }
  312. return $datas;
  313. }
  314. /**
  315. * 获取详情
  316. * @param $id 商家ID
  317. * @param string $type
  318. * @return array|mixed
  319. */
  320. public function getInfoById($id, $type='info', $userId=0)
  321. {
  322. $cacheKey = "caches:merch:{$type}_{$id}";
  323. $info = RedisService::get($cacheKey);
  324. if($info){
  325. return $info;
  326. }
  327. $field = ['a.id','a.name','a.user_id','a.type','a.views_by_day','a.views','a.views_last_at','a.logo','a.category','a.business_scope','a.service_time','a.settle_type','a.deposit','a.delivery_fee','a.start_total','a.score_rate','a.status','a.trade_status','b.username','b.nickname','b.avatar'];
  328. if($type == 'home'){
  329. $field = array_merge($field, ['a.lat','a.lng','a.city','a.address','a.intro','a.albums','a.qualification_imgs','a.other_certificates','b.lat as toLat','b.lng as toLng']);
  330. }else{
  331. $field = array_merge($field, ['a.balance','b.withdraw_total','b.balance as b_balance','a.service_order_num','a.service_order_total']);
  332. }
  333. $info = $this->model->from('merchant as a')->with(['category'])
  334. ->leftJoin('member as b','b.id','=','a.user_id')
  335. ->where(['a.id'=> $id,'a.mark'=>1,'b.mark'=>1])
  336. ->select($field)
  337. ->first();
  338. $info = $info? $info->toArray() : [];
  339. if($info){
  340. if(isset($info['logo'])){
  341. $info['logo'] = $info['logo']? get_image_url($info['logo']) : '';
  342. }
  343. if(isset($info['avatar'])){
  344. $info['avatar'] = $info['avatar']? get_image_url($info['avatar']) : '';
  345. }
  346. if(isset($info['qualification_imgs'])){
  347. $info['qualification_imgs'] = $info['qualification_imgs']? json_decode($info['qualification_imgs'], true) : [];
  348. $info['qualification_imgs'] = $info['qualification_imgs']? get_images_preview($info['qualification_imgs']) : [];
  349. }
  350. if(isset($info['other_certificates'])){
  351. $info['other_certificates'] = $info['other_certificates']? json_decode($info['other_certificates'], true) : [];
  352. $info['other_certificates'] = $info['other_certificates']? get_images_preview($info['other_certificates']) : [];
  353. }
  354. if(isset($info['albums'])){
  355. $info['albums'] = $info['albums']? json_decode($info['albums'], true) : [];
  356. $info['albums'] = $info['albums']? get_images_preview($info['albums']) : [];
  357. }
  358. $info['is_mechanic_apply'] = 0;
  359. if($type == 'home'){
  360. $info['distance'] = 0;
  361. $info['distance_text'] = '';
  362. $info['myLat'] = request()->post('lat',0);
  363. $info['myLng'] = request()->post('lng',0);
  364. if(isset($info['lat']) && $info['lat'] && $info['myLat']){
  365. $info['distance'] = getDistance($info['lat'], $info['lng'], $info['myLat'], $info['myLng']);
  366. $info['distance_text'] = $info['distance']? ($info['distance']<200? '距您 200m以内':'距您 '.formatDistance($info['distance'])) : '在您附近';
  367. }
  368. $info['is_collect'] = MerchantCollectService::make()->checkCollect($userId, $info['id'], 2);
  369. $info['is_mechanic_apply'] = (int)MechanicService::make()->checkApply($userId, $info['id']);
  370. // 浏览量
  371. $data = ['views_by_day'=>$info['views_last_at']<=date('Y-m-d')?1:$info['views_by_day']+1,'views'=>$info['views']+1,'views_last_at'=>date('Y-m-d H:i:s'),'update_time'=>time()];
  372. $this->model->where(['id'=> $info['id'],'mark'=>1])->update($data);
  373. $info['views_by_day'] = $data['views_by_day'];
  374. $info['views_last_at'] = $data['views_last_at'];
  375. $info['views'] = $data['views'];
  376. $info['service_status'] = 2;
  377. $info['service_time'] = isset($info['service_time']) && $info['service_time']? $info['service_time']:'08点~22点';
  378. $serviceTime = $info['service_time']? str_replace('~','~',$info['service_time']):'';
  379. $times = $serviceTime? explode('~',$serviceTime) : [];
  380. $times[0] = isset($times[0]) && $times[0]? $times[0] : '08点';
  381. $times[1] = isset($times[1]) && $times[1]? $times[1] : '22点';
  382. if($times && date('H点')>= $times[0] && date('H点')<=$times[1]){
  383. $info['service_status'] = 1;
  384. }
  385. if($info['trade_status'] != 1){
  386. $info['service_status'] = 2;
  387. }
  388. }else{
  389. $meals = ConfigService::make()->getConfigByCode('shop_deposit');
  390. $meals = $meals? str_replace('|','|', $meals) : '';
  391. $meals = $meals? explode('|', $meals) : [];
  392. $meals = $meals? $meals : [1000];
  393. $info['deposit_meals'] = $meals;
  394. $depositTime = ConfigService::make()->getConfigByCode('shop_deposit_time');
  395. $depositTime = $depositTime>=0? $depositTime : 0;
  396. $info['deposit_time'] = $depositTime;
  397. }
  398. // 二维码
  399. $data = ['mid'=> $info['id'],'scene'=>'merch','type'=>'home'];
  400. $qrcode = MemberService::make()->makeQrcode(json_encode($data));
  401. $info['qrcode'] = $qrcode? get_image_url($qrcode):'';
  402. // 邀请入驻
  403. $data = ['mid'=> $info['id'],'scene'=>'mechanic','type'=>'apply'];
  404. $qrcode = MemberService::make()->makeQrcode(json_encode($data));
  405. $info['apply_qrcode'] = $qrcode? get_image_url($qrcode):'';
  406. // 店铺管理权限
  407. $info['powers'] = [];
  408. if($userId){
  409. $powers = MerchantClerkModel::where(['user_id'=> $userId,'merch_id'=> $info['id'],'mark'=>1])->value('powers');
  410. $info['powers'] = $powers? explode(',', $powers) : [];
  411. }
  412. RedisService::set($cacheKey, $info, rand(3, 5));
  413. }
  414. return $info;
  415. }
  416. /**
  417. * 添加或编辑
  418. * @return array
  419. * @since 2020/11/11
  420. * @author laravel开发员
  421. */
  422. public function edit()
  423. {
  424. $data = request()->all();
  425. // 图片处理
  426. $cover = $data['cover'] ? trim($data['cover']) : '';
  427. if (strpos($cover, "temp")) {
  428. $data['cover'] = save_image($cover, 'ad');
  429. } else {
  430. $data['cover'] = str_replace(IMG_URL, "", $data['cover']);
  431. }
  432. // 开始时间
  433. if (isset($data['start_time'])) {
  434. $data['start_time'] = strtotime($data['start_time']);
  435. }
  436. // 结束时间
  437. if (isset($data['end_time'])) {
  438. $data['end_time'] = strtotime($data['end_time']);
  439. }
  440. return parent::edit($data); // TODO: Change the autogenerated stub
  441. }
  442. /**
  443. * 获取商家缓存数据
  444. * @param $userId
  445. * @param string $field
  446. * @return array|mixed
  447. */
  448. public function getCacheInfoByUser($userId, $field = '')
  449. {
  450. $cacheKey = "caches:merchant:info:temp_{$userId}" . ($field ? '_' . md5($field) : '');
  451. $data = RedisService::get($cacheKey);
  452. if ($data) {
  453. return $data;
  454. }
  455. $field = $field ? $field : 'id,name,user_id,balance,withdraw_total,mobile,category,service_time,pay_password,deposit,service_order_num,service_order_total,trade_status,settle_type,type,logo,status';
  456. $data = $this->model::where(['user_id' => $userId, 'mark' => 1])
  457. ->selectRaw($field)
  458. ->orderBy('id', 'desc')
  459. ->first();
  460. $data = $data ? $data->toArray() : [];
  461. if ($data) {
  462. $data['logo'] = $data['logo']? get_image_url($data['logo']):'';
  463. RedisService::set($cacheKey, $data, rand(3, 5));
  464. }
  465. return $data;
  466. }
  467. /**
  468. * 修改信息
  469. * @param $userId
  470. * @param $params
  471. * @return array|false|int[]
  472. */
  473. public function saveInfo($userId, $params)
  474. {
  475. // 验证是否入驻过和入驻状态
  476. $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
  477. $status = isset($info['status'])? $info['status'] : 0;
  478. $mark = isset($info['mark'])? $info['mark'] : 0;
  479. $merchId = isset($info['id'])? $info['id'] : 0;
  480. if($merchId && empty($info)){
  481. $this->error = 2216;
  482. return false;
  483. }
  484. // 是否被冻结
  485. if($merchId && $status == 3 && $mark){
  486. $this->error = 2202;
  487. return false;
  488. }
  489. // 验证是否是技师
  490. if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
  491. $this->error = 2687;
  492. return false;
  493. }
  494. // 验证账户是否正常
  495. $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
  496. $status = isset($userInfo['status'])? $userInfo['status'] : 0;
  497. if(empty($userInfo) || $status != 1){
  498. $this->error = 2017;
  499. return false;
  500. }
  501. $type = isset($params['type'])? intval($params['type']) : 0;
  502. $category = isset($params['category'])? intval($params['category']) : 0;
  503. $lng = isset($params['lng'])? floatval($params['lng']) : 0;
  504. $lat = isset($params['lat'])? floatval($params['lat']) : 0;
  505. $address = isset($params['address'])? trim($params['address']) : '';
  506. $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
  507. $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
  508. $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
  509. $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
  510. $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
  511. $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
  512. $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
  513. $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
  514. $logoData = isset($params['logo'])? $params['logo'] : [];
  515. $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
  516. $name = isset($params['name'])? $params['name'] : '';
  517. // 验证分类
  518. if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
  519. $this->error = 2203;
  520. return false;
  521. }
  522. // 验证logo
  523. if(empty($logo)){
  524. $this->error = 2204;
  525. return false;
  526. }
  527. // 位置信息
  528. if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
  529. $this->error = 2210;
  530. //return false;
  531. }
  532. // 证书
  533. if(empty($file1)){
  534. $this->error = $type == 1? 2206 : 2211;
  535. return false;
  536. }
  537. if(empty($file2)){
  538. $this->error = 2207;
  539. return false;
  540. }
  541. if(empty($file3)){
  542. $this->error = $type==1? 2208 : 2209;
  543. return false;
  544. }
  545. // 收款码
  546. if(empty($alipayQrcode) || empty($wxpayQrcode)){
  547. $this->error = 2205;
  548. return false;
  549. }
  550. // 入驻数据
  551. $data = [
  552. 'name' => $name,
  553. 'user_id' => $userId,
  554. 'category'=> $category,
  555. 'type'=> $type,
  556. 'logo'=> $logo,
  557. 'albums'=> $albums? $albums : '',
  558. 'qualification_imgs'=> $file1? $file1 : '',
  559. 'other_certificates'=> $file2? $file2 : '',
  560. 'idcard_imgs'=> $file3? $file3 : '',
  561. 'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
  562. 'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
  563. 'lng'=> $lng,
  564. 'lat'=> $lat,
  565. 'address'=> $address,
  566. 'province'=> isset($params['province'])? trim($params['province']) : '',
  567. 'city'=> isset($params['city'])? trim($params['city']) : '',
  568. 'district'=> isset($params['district'])? trim($params['district']) : '',
  569. 'intro'=> isset($params['intro'])? trim($params['intro']) : '',
  570. 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
  571. 'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
  572. 'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
  573. 'create_time'=> time(),
  574. 'update_time'=> time(),
  575. 'status'=> 1,
  576. 'mark'=> 1,
  577. ];
  578. // 写入数据
  579. if($merchId){
  580. if($this->model->where(['id'=> $merchId])->update($data)){
  581. $this->error = 2228;
  582. RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
  583. return ['id'=> $merchId];
  584. }else{
  585. $this->error = 2229;
  586. return false;
  587. }
  588. }else{
  589. if($merchId = $this->model->insertGetId($data)){
  590. $this->error = 2228;
  591. RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
  592. return ['id'=> $merchId];
  593. }else{
  594. $this->error = 2229;
  595. return false;
  596. }
  597. }
  598. }
  599. /**
  600. * 申请入驻
  601. * @param $userId
  602. * @param $params
  603. * @return array|false|int[]
  604. */
  605. public function apply($userId, $params)
  606. {
  607. // 验证是否入驻过和入驻状态
  608. $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
  609. $status = isset($info['status'])? $info['status'] : 0;
  610. $mark = isset($info['mark'])? $info['mark'] : 0;
  611. $merchId = isset($info['id'])? $info['id'] : 0;
  612. if($merchId && $status == 2 && $mark){
  613. $this->error = 2201;
  614. return false;
  615. }
  616. // 是否被冻结
  617. if($merchId && $status == 3 && $mark){
  618. $this->error = 2202;
  619. return false;
  620. }
  621. // 验证是否是技师
  622. if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
  623. $this->error = 2687;
  624. return false;
  625. }
  626. // 验证账户是否正常
  627. $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
  628. $status = isset($userInfo['status'])? $userInfo['status'] : 0;
  629. if(empty($userInfo) || $status != 1){
  630. $this->error = 2017;
  631. return false;
  632. }
  633. $type = isset($params['type'])? intval($params['type']) : 0;
  634. $category = isset($params['category'])? intval($params['category']) : 0;
  635. $lng = isset($params['lng'])? floatval($params['lng']) : 0;
  636. $lat = isset($params['lat'])? floatval($params['lat']) : 0;
  637. $address = isset($params['address'])? trim($params['address']) : '';
  638. $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
  639. $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
  640. $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
  641. $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
  642. $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
  643. $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
  644. $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
  645. $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
  646. $logoData = isset($params['logo'])? $params['logo'] : [];
  647. $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
  648. $name = isset($params['name'])? $params['name'] : '';
  649. // 验证分类
  650. if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
  651. $this->error = 2203;
  652. return false;
  653. }
  654. // 验证logo
  655. if(empty($logo)){
  656. $this->error = 2204;
  657. return false;
  658. }
  659. // 位置信息
  660. if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
  661. $this->error = 2210;
  662. //return false;
  663. }
  664. // 证书
  665. if(empty($file1)){
  666. $this->error = $type == 1? 2206 : 2211;
  667. return false;
  668. }
  669. if(empty($file2)){
  670. $this->error = 2207;
  671. return false;
  672. }
  673. if(empty($file3)){
  674. $this->error = $type==1? 2208 : 2209;
  675. return false;
  676. }
  677. // 收款码
  678. if(empty($alipayQrcode) || empty($wxpayQrcode)){
  679. $this->error = 2205;
  680. return false;
  681. }
  682. // 入驻数据
  683. $data = [
  684. 'name' => $name,
  685. 'user_id' => $userId,
  686. 'category'=> $category,
  687. 'type'=> $type,
  688. 'logo'=> $logo,
  689. 'albums'=> $albums? $albums : '',
  690. 'qualification_imgs'=> $file1? $file1 : '',
  691. 'other_certificates'=> $file2? $file2 : '',
  692. 'idcard_imgs'=> $file3? $file3 : '',
  693. 'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
  694. 'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
  695. 'lng'=> $lng,
  696. 'lat'=> $lat,
  697. 'address'=> $address,
  698. 'province'=> isset($params['province'])? trim($params['province']) : '',
  699. 'city'=> isset($params['city'])? trim($params['city']) : '',
  700. 'district'=> isset($params['district'])? trim($params['district']) : '',
  701. 'intro'=> isset($params['intro'])? trim($params['intro']) : '',
  702. 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
  703. 'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
  704. 'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
  705. 'create_time'=> time(),
  706. 'update_time'=> time(),
  707. 'status'=> 1,
  708. 'mark'=> 1,
  709. ];
  710. // 写入数据
  711. if($merchId){
  712. if($this->model->where(['id'=> $merchId])->update($data)){
  713. $this->error = 2213;
  714. return ['id'=> $merchId];
  715. }else{
  716. $this->error = 2214;
  717. return false;
  718. }
  719. }else{
  720. if($merchId = $this->model->insertGetId($data)){
  721. $this->error = 2215;
  722. return ['id'=> $merchId];
  723. }else{
  724. $this->error = 2214;
  725. return false;
  726. }
  727. }
  728. }
  729. /**
  730. * 获取商家入驻信息
  731. * @param $userId
  732. * @return mixed
  733. */
  734. public function getApplyInfo($userId)
  735. {
  736. $info = $this->model->with(['category'])->where(['user_id'=> $userId,'mark'=>1])
  737. ->orderBy('id','desc')
  738. ->first();
  739. $info = $info? $info->setHidden(['balance','deposit','update_time','mark'])->toArray() : [];
  740. if($info){
  741. $info['logo'] = isset($info['logo']) && $info['logo']? [['url'=> get_image_url($info['logo'])]] : [];
  742. $info['alipay_qrcode'] = isset($info['alipay_qrcode']) && $info['alipay_qrcode']? [['url'=> get_image_url($info['alipay_qrcode'])]] : [];
  743. $info['wxpay_qrcode'] = isset($info['wxpay_qrcode']) && $info['wxpay_qrcode']? [['url'=> get_image_url($info['wxpay_qrcode'])]] : [];
  744. $file1 = isset($info['qualification_imgs']) && $info['qualification_imgs']? json_decode($info['qualification_imgs'], true) : [];
  745. $info['file1'] = $file1? get_images_preview($file1) : [];
  746. $file2 = isset($info['other_certificates']) && $info['other_certificates']? json_decode($info['other_certificates'], true) : [];
  747. $info['file2'] = $file2? get_images_preview($file2) : [];
  748. $file3 = isset($info['idcard_imgs']) && $info['idcard_imgs']? json_decode($info['idcard_imgs'], true) : [];
  749. $info['file3'] = $file3? get_images_preview($file3) : [];
  750. $albums = isset($info['albums']) && $info['albums']? json_decode($info['albums'], true) : [];
  751. $info['albums'] = $albums? get_images_preview($albums) : [];
  752. if(isset($info['category']) && $info['category']){
  753. $info['category_name'] = isset($info['category']['name'])? $info['category']['name'] : '';
  754. $info['category'] = isset($info['category']['id'])? $info['category']['id'] : '';
  755. }
  756. unset($info['qualification_imgs']);
  757. unset($info['other_certificates']);
  758. unset($info['idcard_imgs']);
  759. }
  760. return $info;
  761. }
  762. /**
  763. * @param $userId
  764. * @param $params
  765. * @return bool
  766. */
  767. public function applyConfirm($userId, $params)
  768. {
  769. $id = isset($params['id'])? $params['id'] : 0;
  770. $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
  771. $status = isset($info['status'])? $info['status'] : 0;
  772. if(empty($info) || $id<=0){
  773. $this->error = 2230;
  774. return false;
  775. }
  776. if($status != 1){
  777. $this->error = 2231;
  778. return false;
  779. }
  780. $status = isset($params['status'])? intval($params['status']) : 0;
  781. $auditRemark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  782. if(!in_array($status,[2,3])){
  783. $this->error = 2232;
  784. return false;
  785. }
  786. if($this->model->where(['id'=> $id])->update(['status'=> $status,'audit_remark'=>$auditRemark,'update_time'=>time()])){
  787. $this->error = 1040;
  788. return true;
  789. }else{
  790. $this->error = 1041;
  791. return false;
  792. }
  793. }
  794. /**
  795. * @param $userId
  796. * @param $params
  797. * @return bool
  798. */
  799. public function lock($userId, $params)
  800. {
  801. $id = isset($params['id'])? $params['id'] : 0;
  802. $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
  803. $status = isset($info['status'])? $info['status'] : 0;
  804. if(empty($info) || $id<=0){
  805. $this->error = 2230;
  806. return false;
  807. }
  808. if($status <= 1){
  809. $this->error = 2234;
  810. return false;
  811. }
  812. $agentInfo = AgentModel::where(['user_id'=> $userId,'mark'=>1])->select(['id','user_id','realname'])->first();
  813. $agentId = isset($agentInfo['id'])? $agentInfo['id'] : 0;
  814. if(empty($agentInfo)){
  815. $this->error = 2024;
  816. return false;
  817. }
  818. $status = isset($params['status'])? intval($params['status']) : 0;
  819. $remark = isset($params['remark'])? trim($params['remark']) : '';
  820. if(!in_array($status,[2,3])){
  821. $this->error = 2232;
  822. return false;
  823. }
  824. 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()])){
  825. $this->error = 1035;
  826. return true;
  827. }else{
  828. $this->error = 1036;
  829. return false;
  830. }
  831. }
  832. /**
  833. * 删除
  834. * @return array|false
  835. */
  836. public function delete()
  837. {
  838. // 参数
  839. $id = request()->post('id');
  840. if (empty($id)) {
  841. $this->error = 2014;
  842. return false;
  843. }
  844. $this->error = 1002;
  845. $this->model->where(['id'=> $id,'mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
  846. return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
  847. }
  848. /**
  849. * @param $userId
  850. * @param $params
  851. * @return bool
  852. */
  853. public function modify($userId, $params)
  854. {
  855. // 用户验证
  856. $info = $this->model->where(['user_id' => $userId, 'mark' => 1])
  857. ->select(['id','user_id', 'status'])
  858. ->first();
  859. if (!$info) {
  860. $this->error = 2001;
  861. return false;
  862. }
  863. // 使用状态校验
  864. if ($info['status'] != 2) {
  865. $this->error = 2015;
  866. return false;
  867. }
  868. // 密码校验
  869. $data = ['update_time' => time()];
  870. $payPassword = isset($params['pay_password']) ? $params['pay_password'] : '';
  871. // 手机号验证
  872. $oldMobile = isset($params['old_mobile']) ? $params['old_mobile'] : '';
  873. if (isset($params['old_mobile']) && $oldMobile) {
  874. // 短信验证码
  875. $code = isset($params['old_code']) ? $params['old_code'] : '';
  876. if (empty($code)) {
  877. $this->error = 2013;
  878. return false;
  879. }
  880. if (!SmsService::make()->check($oldMobile, $code, 'modify')) {
  881. $this->error = 1044;
  882. return false;
  883. }
  884. }
  885. // 手机号验证
  886. $mobile = isset($params['mobile']) ? $params['mobile'] : '';
  887. if (isset($params['mobile']) && $mobile) {
  888. $data['mobile'] = $mobile;
  889. $checkInfo = $this->model->where(['mobile' => $mobile, 'mark' => 1])->select(['id','user_id', 'status'])->first();
  890. if ($checkInfo && $checkInfo['user_id'] != $userId) {
  891. // $this->error = 2009;
  892. // return false;
  893. }
  894. // 短信验证码
  895. $code = isset($params['sms_code']) ? $params['sms_code'] : '';
  896. if (empty($code)) {
  897. $this->error = 2013;
  898. return false;
  899. }
  900. if (!SmsService::make()->check($mobile, $code, 'modify')) {
  901. $this->error = SmsService::make()->getError();
  902. return false;
  903. }
  904. }
  905. if(isset($params['settle_type']) && in_array($params['settle_type'],[0,1,2,3])){
  906. $data['settle_type'] = intval($params['settle_type']);
  907. }
  908. if(isset($params['trade_status']) && in_array($params['trade_status'],[1,2])){
  909. $data['trade_status'] = intval($params['trade_status']);
  910. }
  911. if (isset($params['pay_password']) && $payPassword) {
  912. $payPassword = get_password($payPassword);
  913. $data['pay_password'] = $payPassword;
  914. }
  915. // 修改数据
  916. RedisService::clear("caches:merch:detail_{$info['id']}");
  917. RedisService::keyDel("caches:merchant:info:temp*");
  918. $this->model->where(['user_id' => $userId])->update($data);
  919. $this->error = 1008;
  920. return true;
  921. }
  922. /**
  923. * 缴纳保证金
  924. * @param $userId 商家用户
  925. * @param $params
  926. * @return array|false
  927. */
  928. public function deposit($userId, $params)
  929. {
  930. $merchId = isset($params['id'])? $params['id'] : 0;
  931. $money = isset($params['money'])? $params['money'] : 0;
  932. $payType = isset($params['pay_type']) && $params['pay_type']? intval($params['pay_type']) : 10;
  933. if($money<=0){
  934. $this->error = 2031;
  935. return false;
  936. }
  937. if(!in_array($payType, [10,20])){
  938. $this->error = 2032;
  939. return false;
  940. }
  941. $info = $this->model->where(['id'=> $merchId,'mark'=>1])
  942. ->select(['id','name','mobile','balance','deposit','status'])
  943. ->first();
  944. $deposit = isset($info['deposit'])? $info['deposit'] : 0;
  945. $status = isset($info['status'])? $info['status'] : 0;
  946. if($merchId<=0 || empty($info) || $status != 2){
  947. $this->error = 2015;
  948. return false;
  949. }
  950. // 充值订单
  951. $orderNo = get_order_num('DP');
  952. $data = [
  953. 'source_order_no'=> $orderNo,
  954. 'user_id'=> $userId,
  955. 'merch_id'=> $merchId,
  956. 'type'=> 14,
  957. 'coin_type'=> 1,
  958. 'user_type'=> 2,
  959. 'money'=> $money,
  960. 'balance'=> $deposit,
  961. 'date'=> date('Y-m-d'),
  962. 'create_time'=> time(),
  963. 'update_time'=> time(),
  964. 'remark'=> $payType == 10?'微信支付商家保证金':'支付宝支付商家保证金',
  965. 'status'=> 2,
  966. 'mark'=> 1,
  967. ];
  968. if(!$orderId = AccountLogModel::insertGetId($data)){
  969. $this->error = 2037;
  970. return false;
  971. }
  972. // 支付方式
  973. $order = [
  974. 'order_no'=> $orderNo,
  975. 'type'=> 0,
  976. 'pay_type'=> $payType,
  977. 'pay_money'=> $money,
  978. 'body'=> '缴纳保证金订单支付',
  979. ];
  980. switch($payType){
  981. case 20: // 支付宝
  982. $payment = PaymentService::make()->aliPay($info, $order,'deposit');
  983. if(empty($payment)){
  984. DB::rollBack();
  985. $this->error = PaymentService::make()->getError();
  986. return false;
  987. }
  988. break;
  989. case 10: // 微信支付
  990. $payment = PaymentService::make()->wechatPay($info, $order,'deposit');
  991. if(empty($payment)){
  992. DB::rollBack();
  993. $this->error = PaymentService::make()->getError();
  994. return false;
  995. }
  996. break;
  997. default:
  998. $this->error = 1030;
  999. return false;
  1000. }
  1001. $this->error = 2038;
  1002. return [
  1003. 'id'=> $orderId,
  1004. 'payment'=> $payment,
  1005. 'total'=> $money,
  1006. 'order_no'=> $orderNo,
  1007. 'pay_type'=> $payType,
  1008. ];
  1009. }
  1010. /**
  1011. * 退还保证金处理
  1012. * @param $userId 用户
  1013. * @param $params
  1014. * @return bool
  1015. */
  1016. public function rebackDeposit($userId, $params)
  1017. {
  1018. $merchId = isset($params['id'])? $params['id'] : 0;
  1019. if($merchId<=0){
  1020. $this->error = 2039;
  1021. return false;
  1022. }
  1023. $info = $this->model->where(['id'=> $merchId,'mark'=>1])
  1024. ->select(['id','name','mobile','balance','deposit','status'])
  1025. ->first();
  1026. $deposit = isset($info['deposit'])? floatval($info['deposit']) : 0;
  1027. $balance = isset($info['balance'])? floatval($info['balance']) : 0;
  1028. $status = isset($info['status'])? $info['status'] : 0;
  1029. if($merchId<=0 || empty($info) || $status != 2){
  1030. $this->error = 2015;
  1031. return false;
  1032. }
  1033. if($deposit<=0){
  1034. $this->error = 2041;
  1035. return false;
  1036. }
  1037. // 时间限制
  1038. $depositTime = ConfigService::make()->getConfigByCode('shop_deposit_time');
  1039. $depositTime = $depositTime>=0? $depositTime : 0;
  1040. $paymentTime = AccountLogModel::where(['merch_id'=> $merchId,'type'=>14,'coin_type'=>1,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->value('create_time');
  1041. if($depositTime>0 && $paymentTime>0 && $paymentTime + ($depositTime*86400)> time()){
  1042. $this->error = lang(2040,['time'=> $depositTime]);
  1043. return false;
  1044. }
  1045. DB::beginTransaction();
  1046. // 余额
  1047. $updateData = ['balance' => DB::raw("balance + {$deposit}"),'deposit'=>0.00, 'update_time' => time()];
  1048. if(!$this->model->where(['id'=> $merchId])->update($updateData)){
  1049. DB::rollBack();
  1050. $this->error = 2042;
  1051. return false;
  1052. }
  1053. // 退还记录
  1054. $data = [
  1055. 'source_order_no'=> '',
  1056. 'user_id'=> $userId,
  1057. 'merch_id'=> $merchId,
  1058. 'type'=> 14,
  1059. 'coin_type'=> 4,
  1060. 'user_type'=> 2,
  1061. 'money'=> -$deposit,
  1062. 'balance'=> $balance,
  1063. 'date'=> date('Y-m-d'),
  1064. 'create_time'=> time(),
  1065. 'update_time'=> time(),
  1066. 'remark'=> '商家保证金退还',
  1067. 'status'=> 1,
  1068. 'mark'=> 1,
  1069. ];
  1070. if(!$id = AccountLogModel::insertGetId($data)){
  1071. DB::rollBack();
  1072. $this->error = 2042;
  1073. return false;
  1074. }
  1075. DB::commit();
  1076. $params = [
  1077. 'title' => '商家保证金退还到账通知',
  1078. 'body' => "您的商家保证金申请退还已成功,请点击查看详情",
  1079. 'type' => 3, // 1-公告通知,2-订单通知,3-交易通知,4-其他
  1080. 'content' => [
  1081. 'pay_time' => ['name' => '退还时间', 'text' => date('Y-m-d H:i:s')],
  1082. 'money' => ['name' => '金额', 'text' => $deposit],
  1083. 'balance' => ['name' => '当前余额', 'text' => moneyFormat($balance + $deposit,2)],
  1084. 'status' => ['name' => '状态', 'text' => '已到账'],
  1085. ],
  1086. 'click_type' => 'payload',
  1087. 'url' => '/pages/account/index?type=3',
  1088. ];
  1089. PushService::make()->pushMessageByUser($userId, $params, 0);
  1090. $this->error = 2043;
  1091. return true;
  1092. }
  1093. }