ShopClock.Class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Controller\Shop;
  10. use JinDouYun\Model\Enterprise\MEnterprise;
  11. use JinDouYun\Model\Shop\MShopClock;
  12. use JinDouYun\Model\Shop\MShopProject;
  13. use JinDouYun\Model\Shop\MShopRostering;
  14. use JinDouYun\Model\Shop\MShopSubscribe;
  15. use JinDouYun\Model\Shop\MShopTemplate;
  16. use Mall\Framework\Core\ErrorCode;
  17. use Mall\Framework\Core\ResultWrapper;
  18. use Mall\Framework\Core\StatusCode;
  19. use JinDouYun\Cache\ShopCache;
  20. use JinDouYun\Controller\BaseController;
  21. use JinDouYun\Model\Shop\MShop;
  22. use JinDouYun\Cache\TempSaveCache;
  23. class ShopClock extends BaseController
  24. {
  25. private $obj;
  26. private $objShopCache;
  27. private $objTempSaveCache;
  28. public function __construct($isCheckAcl = true, $isMustLogin = true)
  29. {
  30. parent::__construct($isCheckAcl, $isMustLogin);
  31. $this->obj = new MShopClock($this->onlineEnterpriseId, $this->onlineUserId);
  32. $this->objShopCache = new ShopCache();
  33. $this->objTempSaveCache = new TempSaveCache();
  34. }
  35. /**
  36. * 添加和编辑商铺管理公共字段处理方法
  37. *
  38. * @return array
  39. */
  40. public function commonFieldFilter(){
  41. $params = $this->request->getRawJson();
  42. if( empty($params) ){
  43. $this->sendOutput('参数为空', ErrorCode::$paramError );
  44. }
  45. $shopData = [
  46. 'uid' => isset($params['uid']) ? $params['uid'] : '',
  47. 'customer_id' => isset($params['customer_id']) ? $params['customer_id'] : '',
  48. 'project' => isset($params['project']) ? $params['project'] : '',
  49. 'to_price' => isset($params['to_price']) ? $params['to_price'] : '',
  50. 'discount_price' => isset($params['discount_price']) ? $params['discount_price'] : '',
  51. 'pay_price' => isset($params['pay_price']) ? $params['pay_price'] : '',
  52. 'duration' => isset($params['duration']) ? $params['duration'] : '',
  53. 'time' => isset($params['time']) ? $params['time'] : '',
  54. ];
  55. //非暂存则验空
  56. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  57. foreach($shopData as $key => $value){
  58. if(empty($value) && $value !== 0){
  59. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  60. }
  61. }
  62. }
  63. $shopData['remarks']= isset($params['remarks']) ? $params['remarks'] : false;
  64. return $shopData;
  65. }
  66. /**
  67. * 列表
  68. */
  69. public function list()
  70. {
  71. $params = $this->request->getRawJson();
  72. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  73. $selectParams['limit'] = $pageParams['limit'];
  74. $selectParams['offset'] = $pageParams['offset'];
  75. $selectParams['shop_id'] = $this->shopId;
  76. //uid
  77. if(isset($params['uid']) && !empty($params['uid'])){
  78. $selectParams['uid'] = $params['uid'];
  79. }
  80. // 时间
  81. if(isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])){
  82. $selectParams['start_time'] = strtotime($params['start_time']);
  83. $selectParams['end_time'] = strtotime($params['end_time']);
  84. }
  85. $result = $this->obj->list($selectParams);
  86. if ($result->isSuccess()) {
  87. $returnData = $result->getData();
  88. $pageData = [
  89. 'pageIndex' => $params['page'],
  90. 'pageSize' => $params['pageSize'],
  91. 'pageTotal' => $returnData['total'],
  92. ];
  93. parent::sendOutput($returnData['data'], 0, $pageData);
  94. } else {
  95. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  96. }
  97. }
  98. /**
  99. * 添加
  100. * @throws \Exception
  101. */
  102. public function add()
  103. {
  104. $addStaffData = $this->commonFieldFilter();
  105. $addStaffData['shop_id'] = $this->shopId;
  106. $result = $this->obj->insert($addStaffData);
  107. if ($result->isSuccess()) {
  108. parent::sendOutput($result->getData());
  109. } else {
  110. parent::sendOutput($result->getData(), $result->getErrorCode());
  111. }
  112. }
  113. /**
  114. * 详情
  115. * @return void
  116. */
  117. public function details()
  118. {
  119. $where = [];
  120. $id = $this->request->param('id');
  121. if(!empty($id)){
  122. $where['id'] = $id;
  123. }
  124. $result = $this->obj->details($where);
  125. if ($result->isSuccess()) {
  126. parent::sendOutput($result->getData());
  127. } else {
  128. parent::sendOutput($result->getData(), $result->getErrorCode());
  129. }
  130. }
  131. /**
  132. * 修改
  133. * @return void
  134. */
  135. public function update()
  136. {
  137. $id['id'] = $this->request->param('id');
  138. if (empty($id['id'])) {
  139. $this->sendOutput('参数为空', ErrorCode::$paramError);
  140. }
  141. $params = $this->commonFieldFilter();
  142. unset($params['start_time']);
  143. unset($params['end_time']);
  144. unset($params['uid']);
  145. $result = $this->obj->update($params, $id);
  146. if ($result->isSuccess()) {
  147. parent::sendOutput($result->getData());
  148. } else {
  149. parent::sendOutput($result->getData(), $result->getErrorCode());
  150. }
  151. }
  152. public function delete()
  153. {
  154. $id['id'] = $this->request->param('id');
  155. if (empty($id['id'])) {
  156. $this->sendOutput('参数为空', ErrorCode::$paramError);
  157. }
  158. $result = $this->obj->delete($id);
  159. if ($result->isSuccess()) {
  160. parent::sendOutput($result->getData());
  161. } else {
  162. parent::sendOutput($result->getData(), $result->getErrorCode());
  163. }
  164. }
  165. }