GhsService.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace bizHd\ghs\services;
  3. use bizHd\base\services\BaseService;
  4. use bizHd\saas\classes\ApplyClass;
  5. use bizHd\saas\services\ApplyService;
  6. use bizHd\shop\classes\ShopClass;
  7. use common\components\dict;
  8. use common\components\orderSn;
  9. use common\components\util;
  10. use Yii;
  11. class GhsService extends BaseService
  12. {
  13. public static $baseFile = '\bizHd\ghs\classes\GhsClass';
  14. //添加虚拟供货商 ssh 20230305
  15. public static function addVirtualGhs($data, $hdShop)
  16. {
  17. $mobile = orderSn::getMobileSn();
  18. $name = $data['name'] ?? '';
  19. $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  20. if (!empty($hasApply)) {
  21. util::fail('手机号已存在,请和管理员联系');
  22. }
  23. $has = ShopClass::getByCondition(['mobile' => $mobile], true);
  24. if (!empty($has)) {
  25. util::fail('手机号已经存在,请跟管理联系');
  26. }
  27. //将下面的环境定义为批发环境,后继代码可能要用到,不确定,避免风险 ssh 20230306
  28. Yii::$app->params['ptStyle'] = 2;
  29. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => 2, 'ghsMiniOpenId' => ''];
  30. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  31. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  32. $adminId = $admin['id'] ?? 0;
  33. $applyData = [
  34. 'mobile' => $mobile,
  35. 'name' => $name,
  36. 'from' => ApplyClass::FROM_GHS,
  37. 'lat' => '40.023916',
  38. 'long' => '116.298875',
  39. 'live' => 0,
  40. 'adminId' => $adminId,
  41. 'province' => '北京市',
  42. 'city' => '北京市',
  43. 'address' => '上地',
  44. 'showAddress' => '上地',
  45. 'style' => 0,
  46. ];
  47. $apply = ApplyService::replaceGhs($applyData);
  48. $applyId = $apply['id'] ?? 0;
  49. if (empty($applyId)) {
  50. util::fail('没有找到申请记录');
  51. }
  52. \bizGhs\apply\services\ApplyService::pass($applyId);
  53. $ghsShop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => dict::getDict('ptStyle', 'ghs')], true);
  54. if (empty($ghsShop)) {
  55. util::fail('供货商没有生成,请联系管理员');
  56. }
  57. $ghsShopId = $ghsShop->id ?? 0;
  58. $hdShopId = $hdShop->id ?? 0;
  59. \bizGhs\custom\classes\CustomClass::build($ghsShopId, $hdShopId);
  60. }
  61. }