CustomClass.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace bizGhs\custom\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\classes\MerchantClass;
  6. use biz\sj\classes\SjClass;
  7. use common\components\business;
  8. use common\components\imgUtil;
  9. use common\components\util;
  10. use Yii;
  11. use bizHd\base\classes\BaseClass;
  12. class CustomClass extends BaseClass
  13. {
  14. public static $baseFile = '\bizGhs\custom\models\Custom';
  15. //申请开店建立客户关系 ssh 2021.2.28
  16. public static function buildCustom($applyData, $sjId, $shopId)
  17. {
  18. if ($applyData['style'] == SjClass::STYLE_RETAIL) {
  19. if ($applyData['introStyle'] == SjClass::STYLE_SUPPLIER) {
  20. $has = CustomClass::getByCondition(['sjId' => $applyData['introSjId'], 'customSjId' => $sjId, 'customShopId' => $shopId]);
  21. if (empty($has)) {
  22. $customData = [
  23. 'customSjId' => $sjId,//零售商家id
  24. 'customShopId' => $shopId,//零售门店id
  25. 'sjId' => $applyData['introSjId'],//供货商id
  26. 'name' => $applyData['name'],
  27. 'mobile' => $applyData['mobile'],
  28. 'province' => $applyData['province'] ?? '',
  29. 'city' => $applyData['city'] ?? '',
  30. 'dist' => $applyData['dist'] ?? '',
  31. 'address' => $applyData['address'] ?? '',
  32. 'fullAddress' => $applyData['fullAddress'],
  33. 'long' => $applyData['long'],
  34. 'lat' => $applyData['lat'],
  35. ];
  36. CustomClass::addCustom($customData);
  37. $introShopId = $applyData['introShopId'] ?? 0;
  38. $ghsShop = ShopClass::getShopInfo($introShopId);
  39. if (empty($ghsShop)) {
  40. util::fail('没有找到门店');
  41. }
  42. $ghsData = [
  43. 'ghsSjId' => $ghsShop['merchantId'],
  44. 'ghsShopId' => $ghsShop['id'],
  45. 'sjId' => $sjId,
  46. 'shopId' => $sjId,
  47. 'mobile' => $ghsShop['mobile'] ?? '',
  48. 'province' => $ghsShop['province'] ?? '',
  49. 'city' => $ghsShop['city'] ?? '',
  50. 'dist' => $ghsShop['dist'] ?? '',
  51. 'address' => $ghsShop['address'] ?? '',
  52. 'floor' => $ghsShop['floor'] ?? '',
  53. 'fullAddress' => $ghsShop['fullAddress'] ?? '',
  54. 'lat' => $ghsShop['lat'] ?? '',
  55. 'long' => $ghsShop['long'] ?? '',
  56. ];
  57. GhsClass::addGhs($ghsData);
  58. }
  59. }
  60. }
  61. if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
  62. if ($applyData['introStyle'] == SjClass::STYLE_RETAIL) {
  63. $has = CustomClass::getByCondition(['sjId' => $sjId, 'customSjId' => $applyData['introSjId'], 'customShopId' => $applyData['introShopId']]);
  64. if (empty($has)) {
  65. $introSjId = $applyData['introSjId'] ?? 0;
  66. $introShopId = $applyData['introShopId'] ?? 0;
  67. $shop = ShopClass::getShopInfo($introShopId);
  68. $name = $shop['shopName'] ?? '';
  69. $super = ShopClass::getSuper($introShopId);
  70. $mobile = $super['mobile'] ?? '';
  71. $customData = [
  72. 'customSjId' => $introSjId,//零售商id
  73. 'customShopId' => $introShopId,//零售门店id
  74. 'sjId' => $sjId,//供货商id
  75. 'name' => $name,
  76. 'mobile' => $mobile,
  77. 'isOpen' => 1,
  78. 'province' => $applyData['province'] ?? '',
  79. 'city' => $applyData['city'] ?? '',
  80. 'dist' => $applyData['dist'] ?? '',
  81. 'address' => $applyData['address'] ?? '',
  82. 'fullAddress' => $applyData['fullAddress'],
  83. 'long' => $applyData['long'],
  84. 'lat' => $applyData['lat'],
  85. ];
  86. CustomClass::addCustom($customData);
  87. $ghsShop = ShopClass::getShopInfo($shopId);
  88. if (empty($ghsShop)) {
  89. util::fail('没有找到门店');
  90. }
  91. $ghsData = [
  92. 'ghsSjId' => $sjId,
  93. 'ghsShopId' => $shopId,
  94. 'sjId' => $introSjId,
  95. 'shopId' => $introShopId,
  96. 'mobile' => $ghsShop['mobile'] ?? '',
  97. 'province' => $ghsShop['province'] ?? '',
  98. 'city' => $ghsShop['city'] ?? '',
  99. 'dist' => $ghsShop['dist'] ?? '',
  100. 'address' => $ghsShop['address'] ?? '',
  101. 'floor' => $ghsShop['floor'] ?? '',
  102. 'fullAddress' => $ghsShop['fullAddress'] ?? '',
  103. 'lat' => $ghsShop['lat'] ?? '',
  104. 'long' => $ghsShop['long'] ?? '',
  105. ];
  106. GhsClass::addGhs($ghsData);
  107. }
  108. }
  109. }
  110. }
  111. //添加客户 ssh 2021.2.24
  112. public static function addCustom($data)
  113. {
  114. return self::add($data);
  115. }
  116. //获取客户信息 ssh 2021.2.4
  117. public static function getCustom($id)
  118. {
  119. $info = self::getById($id);
  120. if (empty($info)) {
  121. return $info;
  122. }
  123. $respond = self::groupBaseInfo([$info]);
  124. return current($respond);
  125. }
  126. public static function getCustomByIds($ids)
  127. {
  128. $list = self::getByIds($ids, null, 'id');
  129. return self::groupBaseInfo($list);
  130. }
  131. //整合头像等信息 ssh 2021.1.8
  132. public static function groupBaseInfo($list)
  133. {
  134. if (empty($list)) {
  135. return $list;
  136. }
  137. //获取客户信息
  138. $customSjIdList = array_unique(array_filter(array_column($list, 'customSjId')));
  139. $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
  140. foreach ($list as $key => $val) {
  141. $customSjId = $val['customSjId'];
  142. $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
  143. $currentInfo = business::formatMerchantLogo($currentInfo);
  144. $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  145. $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  146. $list[$key]['smallAvatar'] = $smallAvatar;
  147. $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
  148. $list[$key]['avatar'] = $avatar;
  149. $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
  150. $list[$key]['visitTime'] = '03-20 12:00';
  151. $list[$key]['level'] = 0;
  152. $list[$key]['sn'] = $val['id'];
  153. }
  154. return $list;
  155. }
  156. //欠款权限开关 ssh 2021.1.8
  157. public static function debt($custom, $debt)
  158. {
  159. $id = isset($custom['id']) ? $custom['id'] : 0;
  160. self::updateById($id, ['debt' => $debt]);
  161. return true;
  162. }
  163. //权限判断 ssh 2021.1.8
  164. public static function valid($custom, $merchantId)
  165. {
  166. if (empty($custom)) {
  167. util::fail('没有找到客户');
  168. }
  169. if ($custom['sjId'] != $merchantId) {
  170. util::fail('您没有权限操作此客户');
  171. }
  172. }
  173. }