ApiShopSubscribe.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. namespace JinDouYun\Controller\Shop;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Dao\BaseDao;
  5. use JinDouYun\Dao\Customer\DCustomerCardNum;
  6. use JinDouYun\Dao\Department\DStaffComment;
  7. use JinDouYun\Model\Customer\MCustomer;
  8. use JinDouYun\Model\Customer\MCustomerCard;
  9. use JinDouYun\Model\Shop\MShopProject;
  10. use JinDouYun\Model\Shop\MShopRostering;
  11. use JinDouYun\Model\Shop\MShopSubscribe;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\Ding;
  14. use Mall\Framework\Factory;
  15. class ApiShopSubscribe extends BaseController
  16. {
  17. private $obj;
  18. private $objCustomer;
  19. private $objCard;
  20. private $objRostering;
  21. private $objSub;
  22. private $objProject;
  23. public function __construct($isCheckAcl = true, $isMustLogin = false, $checkToken = true, $getAreaCode = false, $checkShopToken = true, $checkSupplierToken = false)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode, $checkShopToken, $checkSupplierToken);
  26. $authorization = $this->request->getServerParam('HTTP_AUTHORIZATION');
  27. if (!empty($authorization)) {
  28. self::getUserIdByAuthorization();
  29. }
  30. $shopToken = $this->request->param('SHOP-TOKEN');
  31. if (!empty($shopToken)){
  32. self::getShopIdByShopToken($shopToken);
  33. }
  34. $this->obj = new MShopSubscribe($this->onlineEnterpriseId, $this->onlineUserId);
  35. $this->objCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  36. $this->objCard = new MCustomerCard($this->onlineEnterpriseId);
  37. $this->objCardNum = new DCustomerCardNum('default');
  38. $this->objRostering = new MShopRostering($this->onlineEnterpriseId, $this->onlineUserId);
  39. $this->objProject = new MShopProject($this->onlineEnterpriseId, $this->onlineUserId);
  40. $this->cache = Factory::cache('user');
  41. }
  42. /**
  43. * 列表
  44. */
  45. public function list()
  46. {
  47. if (empty($this->onlineUserId)) parent::sendOutput('未登录', ErrorCode::$dberror);
  48. $params = $this->request->getRawJson();
  49. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  50. $selectParams['limit'] = $pageParams['limit'];
  51. $selectParams['offset'] = $pageParams['offset'];
  52. $customer = $this->objCustomer->get(['userCenterId' => $this->onlineUserId]);
  53. $selectParams['customer_id'] = $customer['id'];
  54. if ($this->shopId) {
  55. $selectParams['shop_id'] = $this->shopId;
  56. }
  57. //昵称
  58. if (isset($params['nickname']) && !empty($params['nickname'])) {
  59. $selectParams['nickname'] = $params['nickname'];
  60. }
  61. //uid
  62. if (isset($params['uid']) && !empty($params['uid'])) {
  63. $selectParams['uid'] = $params['uid'];
  64. }
  65. if (isset($params['type']) && !empty($params['type'])) {
  66. $selectParams['type'] = $params['type'];
  67. }
  68. // 时间
  69. if (isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])) {
  70. $response = [];
  71. $dt_start = strtotime($params['start_time']);
  72. $dt_end = strtotime($params['end_time']);
  73. while ($dt_start <= $dt_end) {
  74. array_push($response, date('Y-m-d', $dt_start));
  75. $dt_start = strtotime('+1 day', $dt_start);
  76. }
  77. $selectParams['time'] = $response;
  78. }
  79. $result = $this->obj->list($selectParams);
  80. if ($result->isSuccess()) {
  81. $returnData = $result->getData();
  82. $pageData = [
  83. 'pageIndex' => $params['page'],
  84. 'pageSize' => $params['pageSize'],
  85. 'pageTotal' => $returnData['total'],
  86. ];
  87. parent::sendOutput($returnData['data'], 0, $pageData);
  88. } else {
  89. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  90. }
  91. }
  92. /**
  93. * 详情
  94. * @return void
  95. */
  96. public function details()
  97. {
  98. $where = [];
  99. $id = $this->request->param('id');
  100. if (!empty($id)) {
  101. $where['id'] = $id;
  102. }
  103. $result = $this->obj->details($where)->getData();
  104. $project_id = explode(',', $result['project']);
  105. $result['project'] = [];
  106. foreach ($project_id as $vo)
  107. {
  108. $project = $this->objProject->get(['id' => $vo], 'id,name,price,ot_price,info,image');
  109. $result['project'][] = $project;
  110. }
  111. // $project = $this->objProject->select([['id', 'in', $result['project']]], 'id,name,price,ot_price,info,image');
  112. parent::sendOutput($result);
  113. }
  114. /**
  115. * 申请退款
  116. * @return void
  117. */
  118. public function ApplyForRefund()
  119. {
  120. $id = $this->request->param('id');
  121. $refund_remarks = $this->request->param('refund_remarks');
  122. $order = $this->obj->details(['id' => $id]);
  123. if (!$order->isSuccess()) parent::sendOutput('订单不存在',ErrorCode::$dberror);
  124. $order = $order->getData();
  125. if ($order['status'] == 1) parent::sendOutput('订单已完成',ErrorCode::$dberror);
  126. if ($order['refund'] == 1) parent::sendOutput('已申请退款,请耐心等待',ErrorCode::$dberror);
  127. $res = $this->obj->update(['refund' => 1, 'refund_remarks' => $refund_remarks], $id);
  128. if ($res->isSuccess())parent::sendOutput('提交申请成功');
  129. parent::sendOutput($res->getData(), ErrorCode::$dberror);
  130. }
  131. /**
  132. * 员工订单
  133. * @return void
  134. */
  135. public function staff_order()
  136. {
  137. $params = $this->request->getRawJson();
  138. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  139. $selectParams['limit'] = $pageParams['limit'];
  140. $selectParams['offset'] = $pageParams['offset'];
  141. $customer = $this->objCustomer->get(['userCenterId' => $this->onlineUserId]);
  142. $selectParams['customer_id'] = $customer['id'];
  143. if ($this->shopId) {
  144. $selectParams['shop_id'] = $this->shopId;
  145. }
  146. //昵称
  147. if (isset($params['nickname']) && !empty($params['nickname'])) {
  148. $selectParams['nickname'] = $params['nickname'];
  149. }
  150. //uid
  151. if (isset($params['uid']) && !empty($params['uid'])) {
  152. $selectParams['uid'] = $params['uid'];
  153. }
  154. if (isset($params['type']) && !empty($params['type'])) {
  155. $selectParams['type'] = $params['type'];
  156. }
  157. // 时间
  158. if (isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])) {
  159. $response = [];
  160. $dt_start = strtotime($params['start_time']);
  161. $dt_end = strtotime($params['end_time']);
  162. while ($dt_start <= $dt_end) {
  163. array_push($response, date('Y-m-d', $dt_start));
  164. $dt_start = strtotime('+1 day', $dt_start);
  165. }
  166. $selectParams['time'] = $response;
  167. }
  168. $result = $this->obj->list($selectParams);
  169. if ($result->isSuccess()) {
  170. $returnData = $result->getData();
  171. $pageData = [
  172. 'pageIndex' => $params['page'],
  173. 'pageSize' => $params['pageSize'],
  174. 'pageTotal' => $returnData['total'],
  175. ];
  176. parent::sendOutput($returnData['data'], 0, $pageData);
  177. } else {
  178. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  179. }
  180. }
  181. /**
  182. * 员工添加项目
  183. * @return void
  184. */
  185. public function update()
  186. {
  187. $id = $this->request->param('id');
  188. $param['uid'] = $this->request->param('uid');
  189. $param['project'] = $this->request->param('project');
  190. $param['discount_price'] = $this->request->param('discount_price');
  191. $param['to_price'] = $this->request->param('to_price');
  192. $param['stay_price'] = $this->request->param('stay_price');
  193. $data = $this->obj->details(['id' => $id]);
  194. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  195. $project = $this->Mproject->select([['id', 'in', $param['project']]]);
  196. $cost_price = 0;
  197. foreach ($project as $item) {
  198. $cost_price += $item['cost_price'];
  199. }
  200. $param['cost_price'] = $cost_price;
  201. $param['time'] = strtotime($param['time']);
  202. $res = $this->obj->update($param, $id);
  203. if ($res->isSuccess()) {
  204. parent::sendOutput('修改成功');
  205. } else {
  206. parent::sendOutput($res->getData(), $res->getErrorCode());
  207. }
  208. }
  209. /**
  210. * 取消预约订单
  211. * @return void
  212. */
  213. public function cancel()
  214. {
  215. $params = $this->request->getRawJson();
  216. if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
  217. $data = $this->obj->details(['id' => $params['id']]);
  218. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  219. $data = $data->getData();
  220. if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005);
  221. if ($data['paid'] == 1){
  222. $this->obj->refund($data);
  223. }
  224. $res = $this->obj->update(['status' => -1, 'completeTime' => time()], $params['id']);
  225. if ($res->isSuccess()) {
  226. parent::sendOutput('取消成功');
  227. } else {
  228. parent::sendOutput($res->getData(), $res->getErrorCode());
  229. }
  230. }
  231. /**
  232. * 评价
  233. * @return void
  234. */
  235. public function comment()
  236. {
  237. $params = $this->request->getRawJson();
  238. $db = new DStaffComment('default');
  239. $customer = $this->objCustomer->get(['userCenterId' => $this->onlineUserId]);
  240. if (empty($params['uid'])) $this->sendOutput('选择员工', ErrorCode::$paramError);
  241. if (empty($params['comment'])) $this->sendOutput('请填写评论', ErrorCode::$paramError);
  242. if (empty($params['score'])) $this->sendOutput('请添加评分', ErrorCode::$paramError);
  243. $order_id = $params['order_id'];
  244. unset($params['order_id']);
  245. $order = $this->obj->details(['id' => $order_id])->getData();
  246. if ($order['is_evaluate'] == 1) $this->sendOutput('该订单已评价', ErrorCode::$paramError);
  247. $params['customer_id'] = $customer['id'];
  248. $params['en_id'] = $this->onlineEnterpriseId;
  249. $res = $db->insert($params);
  250. if ($res){
  251. $this->obj->update(['is_evaluate' => 1], $order_id);
  252. $this->sendOutput('评价成功');
  253. }
  254. $this->sendOutput('评价失败',ErrorCode::$paramError);
  255. }
  256. /**
  257. * 评价列表
  258. * @return void
  259. */
  260. public function comment_list()
  261. {
  262. $params = $this->request->getRawJson();
  263. $db = new DStaffComment('default');
  264. if (empty($params['id'])) $this->sendOutput('参数为空',ErrorCode::$paramError);
  265. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  266. $limit = $pageParams['limit'];
  267. $offset = $pageParams['offset'];
  268. $id = $params['id'];
  269. $list = $db->select(['uid' => $id, 'en_id' => $this->onlineEnterpriseId], '*', 'id DESC', $limit, $offset);
  270. foreach ($list as &$item)
  271. {
  272. $item['customer'] = $this->objCustomer->get(['id' => $item['customer_id']]);
  273. }
  274. $count = $db->count(['uid' => $id, 'en_id' => $this->onlineEnterpriseId]);
  275. $pageData = [
  276. 'pageIndex' => $params['page'],
  277. 'pageSize' => $params['pageSize'],
  278. 'pageTotal' => $count,
  279. ];
  280. parent::sendOutput($list, 0, $pageData);
  281. }
  282. }