MShopTemplate.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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\DShopProject;
  15. use JinDouYun\Dao\Shop\DShopTemplate;
  16. use JinDouYun\Dao\UserCenter\DUserCenter;
  17. use JinDouYun\Model\Common\Location;
  18. use Mall\Framework\Core\ErrorCode;
  19. use Mall\Framework\Core\StatusCode;
  20. use Mall\Framework\Core\ResultWrapper;
  21. use JinDouYun\Dao\Shop\DShop;
  22. use JinDouYun\Dao\Shop\DEnterpriseBindShop;
  23. use Jindouyun\Cache\EnterpriseCache;
  24. use JinDouYun\Cache\RoleAclCache;
  25. use JinDouYun\Cache\ShopCache;
  26. use JinDouYun\Cache\SysAreaChinaCache;
  27. use JinDouYun\Cache\GoodsBasicRelevant;
  28. use JinDouYun\Model\ShopPartner\MShopPartner;
  29. use JinDouYun\Model\Stock\MWarehouse;
  30. use JinDouYun\Model\SysAreaChina\MSysAreaChina;
  31. use JinDouYun\Model\Customer\MCustomer;
  32. use JinDouYun\Model\Enterprise\MEnterprise;
  33. use JinDouYun\Model\Department\MStaff;
  34. use JinDouYun\Model\MBaseModel;
  35. use Monolog\Handler\IFTTTHandler;
  36. class MShopTemplate extends MBaseModel
  37. {
  38. private $obj;
  39. private $cutTable = 250000;
  40. private $enterpriseId;
  41. private $userCenterId;
  42. private $objMShopPartner;
  43. private $objMStaff;
  44. public function __construct($enterpriseId, $userCenterId = '')
  45. {
  46. $this->enterpriseId = $enterpriseId;
  47. $this->userCenterId = $userCenterId;
  48. parent::__construct($this->enterpriseId, $this->userCenterId);
  49. $this->obj = new DShopTemplate('default');
  50. }
  51. /**
  52. * 列表
  53. * @param $where
  54. * @return mixed
  55. */
  56. public function list($where)
  57. {
  58. $limit = $where['limit'];
  59. unset($where['limit']);
  60. $offset = $where['offset'];
  61. unset($where['offset']);
  62. $dbResult = $this->obj->select($where, '*', 'id DESC', $limit, $offset);
  63. $count = $this->obj->count($where);
  64. if ($dbResult === false) {
  65. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  66. }
  67. foreach ($dbResult as &$item)
  68. {
  69. $item['time'] = json_decode($item['time']);
  70. }
  71. $return = [
  72. 'data' => $dbResult,
  73. 'total' => $count,
  74. ];
  75. if($return === false){
  76. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  77. }else{
  78. return ResultWrapper::success($return);
  79. }
  80. }
  81. /**
  82. * 详情
  83. * @param $where
  84. * @return mixed
  85. */
  86. public function details($where)
  87. {
  88. if(empty($where)){
  89. return ResultWrapper::success($where);
  90. }
  91. $dbResult = $this->obj->get($where);
  92. $dbResult['time'] = json_decode($dbResult['time']);
  93. if($dbResult === false){
  94. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  95. }
  96. return ResultWrapper::success(self::formatInfo($dbResult));
  97. }
  98. /**
  99. * Doc: (des="添加")
  100. * User: XMing
  101. * Date: 2020/7/15
  102. * Time: 10:42 上午
  103. * @throws Exception
  104. * @param array $params
  105. * @return ResultWrapper
  106. */
  107. public function insert(array $params)
  108. {
  109. $res = $this->obj->insert($params);
  110. if ($res){
  111. return ResultWrapper::success('添加成功');
  112. }else{
  113. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  114. }
  115. }
  116. public function update($params, $id)
  117. {
  118. $data = $this->obj->get($id);
  119. if (!$data){
  120. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  121. }
  122. $dbResult = $this->obj->update($params,$id);
  123. if($dbResult === false){
  124. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  125. }
  126. return ResultWrapper::success('修改成功');
  127. }
  128. /**
  129. * 格式数据详情
  130. * @param $data
  131. * @return mixed
  132. */
  133. public function formatInfo($data)
  134. {
  135. return $data;
  136. }
  137. public function delete($where)
  138. {
  139. $res = $this->obj->delete($where);
  140. if ($res){
  141. return ResultWrapper::success('删除成功');
  142. }
  143. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  144. }
  145. }