GhsController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\classes\SjClass;
  4. use bizGhs\ghs\classes\GhsClass;
  5. use bizHd\saas\classes\ApplyClass;
  6. use bizHd\saas\services\ApplyService;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\orderSn;
  10. use common\components\stringUtil;
  11. use Yii;
  12. use common\components\util;
  13. use bizGhs\order\classes\PurchaseOrderClass;
  14. class GhsController extends BaseController
  15. {
  16. public function actionModifyName()
  17. {
  18. $get = Yii::$app->request->get();
  19. $id = $get['id'] ?? 0;
  20. $name = $get['name'] ?? '';
  21. $ghs = GhsClass::getById($id, true);
  22. if (empty($ghs)) {
  23. util::fail('没有找到供货商');
  24. }
  25. if ($ghs->ownMainId != $this->mainId) {
  26. util::fail('不是你的供货商');
  27. }
  28. if (empty($name)) {
  29. util::fail('请填写名称');
  30. }
  31. if (stringUtil::getWordNum($name) > 27) {
  32. util::fail('名称不能超过27个汉字');
  33. }
  34. $ghs->name = $name;
  35. $ghs->py = stringUtil::py($name);
  36. $ghs->save();
  37. util::complete('修改成功');
  38. }
  39. //添加供货商 ssh 20210611
  40. public function actionAdd()
  41. {
  42. $post = Yii::$app->request->post();
  43. $location = $post['location'] ?? '';
  44. $mobile = $post['mobile'] ?? '';
  45. $name = $post['name'] ?? '';
  46. if (empty($name)) {
  47. util::fail('名称不能为空');
  48. }
  49. if (stringUtil::getWordNum($name) > 27) {
  50. util::fail('名称不能超过27个汉字');
  51. }
  52. $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
  53. if (!empty($hasGhsList)) {
  54. foreach ($hasGhsList as $hasGhs) {
  55. $hasGhsName = $hasGhs->name ?? '';
  56. if ($hasGhsName == $name) {
  57. util::fail('名称已经存在了');
  58. }
  59. }
  60. }
  61. if (!empty($mobile)) {
  62. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  63. if (!empty($has)) {
  64. $connection = Yii::$app->db;
  65. $transaction = $connection->beginTransaction();
  66. try {
  67. $shopId = $this->shopId;
  68. $currentShopId = $has['shopId'] ?? 0;
  69. if (empty($currentShopId)) {
  70. util::fail('添加失败');
  71. }
  72. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  73. if (!empty($hasGhs)) {
  74. $name = $hasGhs->name ?? '';
  75. util::fail("手机已添加过了,供货商名称:【{$name}】");
  76. }
  77. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  78. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  79. $transaction->commit();
  80. util::success($ghs);
  81. } catch (\Exception $exception) {
  82. $transaction->rollBack();
  83. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  84. util::fail('添加供货商没有成功');
  85. }
  86. util::fail('添加失败,请联系管理员');
  87. }
  88. }
  89. $connection = Yii::$app->db;
  90. $transaction = $connection->beginTransaction();
  91. try {
  92. if (empty($mobile)) {
  93. //获取虚拟手机号
  94. $mobile = orderSn::getMobileSn();
  95. }
  96. $sjId = $this->sjId;
  97. $shopId = $this->shopId;
  98. $sjName = $this->sj->name ?? '';
  99. $address = $post['address'] ?? '';
  100. $applyData = [
  101. 'name' => $name,
  102. 'licenseNo' => $mobile,
  103. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  104. 'mobile' => $mobile,
  105. 'introSjId' => $sjId,
  106. 'introSjName' => $sjName,
  107. 'introShopId' => $shopId,
  108. 'introStyle' => SjClass::STYLE_SUPPLIER,
  109. 'from' => ApplyClass::FROM_GHS,
  110. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  111. 'address' => $address,
  112. 'status' => ApplyClass::STATUS_PASS,
  113. ];
  114. $apply = ApplyService::replaceKmGhs($applyData);
  115. $id = $apply['id'] ?? 0;
  116. $respond = \bizJd\apply\services\ApplyService::pass($id);
  117. $shop = $respond['shop'] ?? [];
  118. $sj = $respond['sj'] ?? [];
  119. $currentSjId = $sj['id'] ?? 0;
  120. $currentShopId = $shop->id ?? 0;
  121. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  122. if (empty($currentShopId)) {
  123. util::fail('供货商没有添加成功!');
  124. }
  125. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  126. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  127. if (is_numeric($location)) {
  128. //本地批发商的标记
  129. $ghsId = $ghs['id'] ?? 0;
  130. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  131. }
  132. $transaction->commit();
  133. util::success($ghs);
  134. } catch (\Exception $exception) {
  135. $transaction->rollBack();
  136. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  137. util::fail('添加供货商没有成功');
  138. }
  139. }
  140. //供货商列表 ssh 2021.1.18
  141. public function actionList()
  142. {
  143. $get = Yii::$app->request->get();
  144. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  145. $where = ['ownShopId' => $this->shopId];
  146. if (!empty($name)) {
  147. if (stringUtil::isLetter($name)) {
  148. $where['py'] = ['like', $name];
  149. } else {
  150. $where['name'] = ['like', $name];
  151. }
  152. }
  153. $location = $get['location'] ?? '';
  154. if (is_numeric($location)) {
  155. $where['location'] = $location;
  156. }
  157. //采购限制访问,有多处要同步修改,关键词cg_limit_access
  158. if (getenv('YII_ENV') == 'production') {
  159. //纯彩花艺
  160. if ($this->mainId == 10) {
  161. if (in_array($this->adminId, [37, 988, 14346]) == false) {
  162. util::fail('没有数据哦');
  163. }
  164. }
  165. //天天鲜花十堰店
  166. if ($this->mainId == 7184) {
  167. if (in_array($this->adminId, [8340, 8345, 9433]) == false) {
  168. util::fail('没有数据哦');
  169. }
  170. }
  171. }
  172. $list = GhsClass::getGhsList($where);
  173. $staff = $this->shopAdmin;
  174. if (isset($staff->finance) == false || $staff->finance == 0) {
  175. $totalDebtAmount = 0;
  176. //没有财务权限的人不让看到欠款多少
  177. if (!empty($list['list'])) {
  178. foreach ($list['list'] as $key => $val) {
  179. $list['list'][$key]['debtAmount'] = 0;
  180. }
  181. }
  182. } else {
  183. //累计总欠款
  184. $totalDebtAmount = PurchaseOrderClass::sum(['mainId' => $this->mainId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice');
  185. }
  186. $list['totalDebtAmount'] = $totalDebtAmount;
  187. util::success($list);
  188. }
  189. //下载供货商 ssh 20240506
  190. public function actionDownloadGhs()
  191. {
  192. //$get = Yii::$app->request->get();
  193. $mainId = $this->mainId;
  194. $respond = GhsClass::getGhsFile($mainId);
  195. $file = $respond['file'] ?? '';
  196. $shortFile = $respond['shortFile'] ?? '';
  197. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  198. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  199. }
  200. }