MShopKey.Class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Model\Shop;
  10. use Exception;
  11. use JinDouYun\Controller\Common\Logger;
  12. use JinDouYun\Dao\Department\DStaff;
  13. use JinDouYun\Dao\GoodsManage\DGoodsBasic;
  14. use JinDouYun\Dao\Shop\DShopKey;
  15. use JinDouYun\Dao\Shop\DShopProject;
  16. use JinDouYun\Dao\Shop\DShopTemplate;
  17. use JinDouYun\Dao\UserCenter\DUserCenter;
  18. use JinDouYun\Model\Common\Location;
  19. use Mall\Framework\Core\ErrorCode;
  20. use Mall\Framework\Core\StatusCode;
  21. use Mall\Framework\Core\ResultWrapper;
  22. use JinDouYun\Dao\Shop\DShop;
  23. use JinDouYun\Dao\Shop\DEnterpriseBindShop;
  24. use Jindouyun\Cache\EnterpriseCache;
  25. use JinDouYun\Cache\RoleAclCache;
  26. use JinDouYun\Cache\ShopCache;
  27. use JinDouYun\Cache\SysAreaChinaCache;
  28. use JinDouYun\Cache\GoodsBasicRelevant;
  29. use JinDouYun\Model\ShopPartner\MShopPartner;
  30. use JinDouYun\Model\Stock\MWarehouse;
  31. use JinDouYun\Model\SysAreaChina\MSysAreaChina;
  32. use JinDouYun\Model\Customer\MCustomer;
  33. use JinDouYun\Model\Enterprise\MEnterprise;
  34. use JinDouYun\Model\Department\MStaff;
  35. use JinDouYun\Model\MBaseModel;
  36. use Monolog\Handler\IFTTTHandler;
  37. class MShopKey extends MBaseModel
  38. {
  39. private $obj;
  40. private $cutTable = 250000;
  41. private $enterpriseId;
  42. private $userCenterId;
  43. private $objMShopPartner;
  44. private $objMStaff;
  45. public function __construct($enterpriseId, $userCenterId = '')
  46. {
  47. $this->enterpriseId = $enterpriseId;
  48. $this->userCenterId = $userCenterId;
  49. parent::__construct($this->enterpriseId, $this->userCenterId);
  50. $this->obj = new DShopKey('default');
  51. }
  52. /**
  53. * 列表
  54. * @param $where
  55. * @return mixed
  56. */
  57. public function list($where)
  58. {
  59. $limit = $where['limit'];
  60. unset($where['limit']);
  61. $offset = $where['offset'];
  62. unset($where['offset']);
  63. $file = ' a.* ';
  64. $sql = 'SELECT'.$file.'FROM qianniao_shop_template AS a
  65. WHERE shop_id = '. $where['shop_id'];
  66. if(isset($where['name'])) {
  67. $sql .= ' AND a.name LIKE "%' . $where['name'] . '%"';
  68. }
  69. $total = count((array) $this->obj->query($sql));
  70. $sql .= ' ORDER BY createTime DESC LIMiT '.$offset.','.$limit;
  71. $dbResult = $this->obj->query($sql);
  72. if ($dbResult === false) {
  73. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  74. }
  75. $return = [
  76. 'data' => $dbResult,
  77. 'total' => ($total) ? intval($total) : 0,
  78. ];
  79. if($return === false){
  80. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  81. }else{
  82. return ResultWrapper::success($return);
  83. }
  84. }
  85. /**
  86. * 详情
  87. * @param $where
  88. * @return mixed
  89. */
  90. public function details($where)
  91. {
  92. $where['enterprise_id'] = $this->enterpriseId;
  93. if(empty($where)){
  94. return ResultWrapper::success($where);
  95. }
  96. $dbResult = $this->obj->get($where);
  97. if($dbResult === false){
  98. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  99. }
  100. return ResultWrapper::success(self::formatInfo($dbResult));
  101. }
  102. /**
  103. * Doc: (des="添加")
  104. * User: XMing
  105. * Date: 2020/7/15
  106. * Time: 10:42 上午
  107. * @throws Exception
  108. * @param array $params
  109. * @return ResultWrapper
  110. */
  111. public function insert(array $params)
  112. {
  113. $params['enterprise_id'] = $this->enterpriseId;
  114. $res = $this->obj->insert($params);
  115. if ($res){
  116. return ResultWrapper::success('添加成功');
  117. }else{
  118. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  119. }
  120. }
  121. public function update($params, $id)
  122. {
  123. $data = $this->obj->get($id);
  124. if (!$data){
  125. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  126. }
  127. $dbResult = $this->obj->update($params,$id);
  128. if($dbResult === false){
  129. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  130. }
  131. return ResultWrapper::success('修改成功');
  132. }
  133. /**
  134. * 格式数据详情
  135. * @param $data
  136. * @return mixed
  137. */
  138. public function formatInfo($data)
  139. {
  140. return $data;
  141. }
  142. public function delete($id)
  143. {
  144. $res = $this->obj->delete(['id' => $id]);
  145. if ($res){
  146. return ResultWrapper::success('删除成功');
  147. }
  148. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  149. }
  150. }