CustomerCard.Class.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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\Customer;
  10. use AlibabaCloud\SDK\Dingtalk\Vbizfinance_1_0\Models\QueryReceiptsBaseInfoResponseBody\list_\project;
  11. use JinDouYun\Model\Customer\MCustomerCard;
  12. use JinDouYun\Model\Department\MStaff;
  13. use JinDouYun\Model\Enterprise\MEnterprise;
  14. use JinDouYun\Model\Shop\MShopProject;
  15. use JinDouYun\Model\Shop\MShopRostering;
  16. use JinDouYun\Model\Shop\MShopSubscribe;
  17. use JinDouYun\Model\Shop\MShopTemplate;
  18. use Mall\Framework\Core\ErrorCode;
  19. use Mall\Framework\Core\ResultWrapper;
  20. use Mall\Framework\Core\StatusCode;
  21. use JinDouYun\Cache\ShopCache;
  22. use JinDouYun\Controller\BaseController;
  23. use JinDouYun\Model\Shop\MShop;
  24. use JinDouYun\Cache\TempSaveCache;
  25. class CustomerCard extends BaseController
  26. {
  27. private $obj;
  28. private $objShopCache;
  29. private $objTempSaveCache;
  30. public function __construct($isCheckAcl = true, $isMustLogin = true)
  31. {
  32. parent::__construct($isCheckAcl, $isMustLogin);
  33. $this->obj = new MCustomerCard($this->onlineEnterpriseId, $this->onlineUserId);
  34. $this->objShopCache = new ShopCache();
  35. $this->objTempSaveCache = new TempSaveCache();
  36. }
  37. /**
  38. * 添加和编辑商铺管理公共字段处理方法
  39. *
  40. * @return array
  41. */
  42. public function commonFieldFilter(){
  43. $params = $this->request->getRawJson();
  44. if( empty($params) ){
  45. $this->sendOutput('参数为空', ErrorCode::$paramError );
  46. }
  47. $shopData = [
  48. 'uid' => isset($params['uid']) ? $params['uid'] : '',
  49. 'customer_id' => isset($params['customer_id']) ? $params['customer_id'] : '',
  50. 'project' => isset($params['project']) ? $params['project'] : '',
  51. 'time' => isset($params['time']) ? $params['time'] : '',
  52. ];
  53. //非暂存则验空
  54. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  55. foreach($shopData as $key => $value){
  56. if(empty($value) && $value !== 0){
  57. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  58. }
  59. }
  60. }
  61. $shopData['remarks']= isset($params['remarks']) ? $params['remarks'] : false;
  62. $shopData['pay_price']= isset($params['pay_price']) ? $params['pay_price'] : false;
  63. $shopData['to_price']= isset($params['to_price']) ? $params['to_price'] : false;
  64. $shopData['discount_price']= isset($params['discount_price']) ? $params['discount_price'] : false;
  65. return $shopData;
  66. }
  67. public function add()
  68. {
  69. $addStaffData = $this->commonFieldFilter();
  70. $project = $this->Mproject->select([['id', 'in', $addStaffData['project']]]);
  71. $addStaffData['shop_id'] = $this->shopId;
  72. $price = 0;
  73. $service_time = 0;
  74. foreach ($project as $item)
  75. {
  76. $price += $item['price'];
  77. $service_time += $item['service_time'];
  78. }
  79. if ($addStaffData['to_price']){
  80. $to_price = $addStaffData['to_price'];
  81. }else{
  82. $to_price = $price;
  83. }
  84. if ($addStaffData['pay_price']) {
  85. $pay_price = $addStaffData['pay_price'];
  86. }else{
  87. $pay_price = $price - $addStaffData['discount_price'];
  88. }
  89. $addStaffData['pay_price'] = $pay_price;
  90. $addStaffData['to_price'] = $to_price;
  91. $addStaffData['service_time'] = $service_time;
  92. $addStaffData['duration'] = $service_time;
  93. $result = $this->obj->insert($addStaffData);
  94. if ($result){
  95. parent::sendOutput('添加成功');
  96. }else{
  97. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  98. }
  99. }
  100. /**
  101. * 修改2
  102. * @return void
  103. */
  104. public function update()
  105. {
  106. $id = $this->request->param('id');
  107. $param['project'] = $this->request->param('project');
  108. $param['discount_price'] = $this->request->param('discount_price');
  109. $param['to_price'] = $this->request->param('to_price');
  110. $param['pay_price'] = $this->request->param('pay_price');
  111. $param['time'] = $this->request->param('time');
  112. $param['remarks'] = $this->request->param('remarks');
  113. $data = $this->obj->details(['id' => $id]);
  114. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  115. $param['time'] = strtotime($param['time']);
  116. $res = $this->obj->update($param, $id);
  117. if ($res->isSuccess()) {
  118. parent::sendOutput('修改成功');
  119. } else {
  120. parent::sendOutput($res->getData(), $res->getErrorCode());
  121. }
  122. }
  123. /**
  124. * 列表
  125. */
  126. public function list()
  127. {
  128. $params = $this->request->getRawJson();
  129. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  130. $selectParams['limit'] = $pageParams['limit'];
  131. $selectParams['offset'] = $pageParams['offset'];
  132. $selectParams['shop_id'] = $this->shopId;
  133. //昵称
  134. if(isset($params['nickname']) && !empty($params['nickname'])){
  135. $selectParams['nickname'] = $params['nickname'];
  136. }
  137. //uid
  138. if(isset($params['uid']) && !empty($params['uid'])){
  139. $selectParams['uid'] = $params['uid'];
  140. }
  141. if(isset($params['customer_id']) && !empty($params['customer_id'])){
  142. $selectParams['customer_id'] = $params['customer_id'];
  143. }
  144. // 时间
  145. if(isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])){
  146. $response = [];
  147. $dt_start = strtotime($params['start_time']);
  148. $dt_end = strtotime($params['end_time']);
  149. while ($dt_start <= $dt_end) {
  150. array_push($response, date('Y-m-d', $dt_start));
  151. $dt_start = strtotime('+1 day', $dt_start);
  152. }
  153. $selectParams['time'] = $response;
  154. }
  155. $result = $this->obj->list($selectParams);
  156. if ($result->isSuccess()) {
  157. $returnData = $result->getData();
  158. $pageData = [
  159. 'pageIndex' => $params['page'],
  160. 'pageSize' => $params['pageSize'],
  161. 'pageTotal' => $returnData['total'],
  162. ];
  163. parent::sendOutput($returnData['data'], 0,$pageData);
  164. } else {
  165. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  166. }
  167. }
  168. public function complete()
  169. {
  170. $params = $this->request->getRawJson();
  171. if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
  172. $data = $this->obj->details(['id' => $params['id']]);
  173. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  174. $data = $data->getData();
  175. if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005);
  176. $reward = 0;
  177. foreach ($data['project'] as $item){
  178. $reward += $item['price'] * ($item['commission']/100);
  179. }
  180. $this->staff->service($reward, $data['uid'], $this->shopId, $data['id']);
  181. $res = $this->obj->update(['status'=> 1, 'paid' => 1], $params['id']);
  182. if ($res->isSuccess()) {
  183. parent::sendOutput('修改成功');
  184. } else {
  185. parent::sendOutput($res->getData(), $res->getErrorCode());
  186. }
  187. }
  188. /**
  189. * 取消预约订单
  190. * @return void
  191. */
  192. public function cancel()
  193. {
  194. $params = $this->request->getRawJson();
  195. if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
  196. $data = $this->obj->details(['id' => $params['id']]);
  197. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  198. $data = $data->getData();
  199. if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005);
  200. $res = $this->obj->update(['status'=> -1], $params['id']);
  201. if ($res->isSuccess()) {
  202. parent::sendOutput('取消成功');
  203. } else {
  204. parent::sendOutput($res->getData(), $res->getErrorCode());
  205. }
  206. }
  207. /**
  208. * 详情
  209. * @return void
  210. */
  211. public function details()
  212. {
  213. $params = $this->request->getRawJson();
  214. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  215. $selectParams['limit'] = $pageParams['limit'];
  216. $selectParams['offset'] = $pageParams['offset'];
  217. if(!empty($params['id'])){
  218. $selectParams['id'] = $params['id'];
  219. }
  220. $result = $this->obj->details($selectParams);
  221. if ($result->isSuccess()) {
  222. parent::sendOutput($result->getData());
  223. } else {
  224. parent::sendOutput($result->getData(), $result->getErrorCode());
  225. }
  226. }
  227. public function delete()
  228. {
  229. $id['id'] = $this->request->param('id');
  230. if (empty($id['id'])) {
  231. $this->sendOutput('参数为空', ErrorCode::$paramError);
  232. }
  233. $result = $this->obj->delete($id);
  234. if ($result->isSuccess()) {
  235. parent::sendOutput($result->getData());
  236. } else {
  237. parent::sendOutput($result->getData(), $result->getErrorCode());
  238. }
  239. }
  240. }