ShopClass.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace bizMall\merchant\classes;
  3. use common\components\dirUtil;
  4. use common\components\httpUtil;
  5. use common\components\qrCodeUtil;
  6. use common\components\util;
  7. use common\components\wxUtil;
  8. use Yii;
  9. use bizMall\base\classes\BaseClass;
  10. class ShopClass extends BaseClass
  11. {
  12. public static $baseFile = '\bizMall\merchant\models\Shop';
  13. public static function getShopList($where)
  14. {
  15. $list = self::getList('*', $where, 'addTime DESC');
  16. return $list;
  17. }
  18. //获取商家默认的门店ID ssh 2020.1.19
  19. public static function getDefaultShopId($merchant)
  20. {
  21. return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
  22. }
  23. //创建门店 ssh 2020.2.8
  24. public static function addShop($data)
  25. {
  26. $data['createTime'] = date("Y-m-d H:i:s");
  27. $shopName = isset($data['shopName']) ? $data['shopName'] : '';
  28. if (empty($shopName)) {
  29. util::fail('请填写门店名称');
  30. }
  31. $exists = self::getByCondition(['sjId' => $data['sjId'], 'shopName' => $shopName]);
  32. if (!empty($exists)) {
  33. util::fail('门店名称已经存在');
  34. }
  35. $shop = self::add($data);
  36. return $shop;
  37. }
  38. //更新门店 ssh 2020.2.29
  39. public static function updateShop($id, $data)
  40. {
  41. $shopName = isset($data['shopName']) ? $data['shopName'] : '';
  42. $sjId = $data['sjId'];
  43. $findShop = self::getByCondition(['sjId' => $sjId, 'shopName' => $shopName]);
  44. if (!empty($findShop) && $findShop['id'] != $id) {
  45. util::fail('门店名称已经存在');
  46. }
  47. return self::updateById($id, $data);
  48. }
  49. //取商家所有门店 ssh 2020.2.29
  50. public static function getAllShop($sjId)
  51. {
  52. return self::getAllByCondition(['sjId' => $sjId]);
  53. }
  54. //验证所属权限 ssh 2020.2.29
  55. public static function valid($shop, $sjId)
  56. {
  57. if (empty($shop)) {
  58. util::fail('门店无效');
  59. }
  60. if (isset($shop['sjId']) == false || $shop['sjId'] != $sjId) {
  61. util::fail('您无法访问');
  62. }
  63. }
  64. //删除门店 ssh 2020.3.1
  65. public static function deleteShop($shop)
  66. {
  67. if (isset($shop['default']) && $shop['default'] == 1) {
  68. util::fail('默认门店不允许删除');
  69. }
  70. $id = $shop['id'];
  71. self::updateById($id, ['delStatus' => 1]);
  72. }
  73. //生成收款码 ssh 2020.3.9
  74. public static function generateGatheringCode($sjId, $shopId)
  75. {
  76. $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$sjId}&shopId=" . $shopId;
  77. //强制转成https
  78. $url = httpUtil::becomeHttps($url);
  79. $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 10);
  80. return $gatheringCode;
  81. }
  82. }