CustomClass.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace bizGhs\custom\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\MerchantClass;
  5. use common\components\business;
  6. use common\components\imgUtil;
  7. use common\components\util;
  8. use bizHd\base\classes\BaseClass;
  9. class CustomClass extends BaseClass
  10. {
  11. public static $baseFile = '\bizGhs\custom\models\Custom';
  12. const IS_DEBT_NO = 0;
  13. const IS_DEBT_YES = 1;
  14. //建立客户和供应商关系
  15. public static function build($ghsShopId, $hdShopId)
  16. {
  17. return GhsClass::build($ghsShopId, $hdShopId, 2);
  18. }
  19. //添加客户 ssh 2021.2.24
  20. public static function addCustom($data)
  21. {
  22. return self::add($data);
  23. }
  24. //获取客户信息 ssh 2021.2.4
  25. public static function getCustom($id)
  26. {
  27. $info = self::getById($id);
  28. if (empty($info)) {
  29. return $info;
  30. }
  31. $respond = self::groupBaseInfo([$info]);
  32. return current($respond);
  33. }
  34. public static function getCustomByIds($ids)
  35. {
  36. $list = self::getByIds($ids, null, 'id');
  37. return self::groupBaseInfo($list);
  38. }
  39. //整合头像等信息 ssh 2021.1.8
  40. public static function groupBaseInfo($list)
  41. {
  42. if (empty($list)) {
  43. return $list;
  44. }
  45. //获取客户信息
  46. $customSjIdList = array_unique(array_filter(array_column($list, 'sjId')));
  47. $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
  48. foreach ($list as $key => $val) {
  49. $customSjId = $val['sjId'];
  50. $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
  51. $currentInfo = business::formatMerchantLogo($currentInfo);
  52. $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  53. $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  54. $list[$key]['smallAvatar'] = $smallAvatar;
  55. $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
  56. $list[$key]['avatar'] = $avatar;
  57. $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
  58. $list[$key]['visitTime'] = '03-20 12:00';
  59. $list[$key]['level'] = 0;
  60. $list[$key]['sn'] = $val['id'];
  61. }
  62. return $list;
  63. }
  64. //欠款权限开关 ssh 2021.1.8
  65. public static function debt($custom, $debt)
  66. {
  67. $id = isset($custom['id']) ? $custom['id'] : 0;
  68. self::updateById($id, ['debt' => $debt]);
  69. return true;
  70. }
  71. //权限判断 ssh 2021.1.8
  72. public static function valid($custom, $shopId)
  73. {
  74. if (empty($custom)) {
  75. util::fail('没有找到客户');
  76. }
  77. if ($custom['ownShopId'] != $shopId) {
  78. util::fail('您没有权限操作此客户');
  79. }
  80. }
  81. }