Cashier.Class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <?php
  2. namespace JInDouYun\Controller\Cashier;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Cashier\MCashier;
  5. use JinDouYun\Model\Cashier\MCashierCart;
  6. use JinDouYun\Model\Market\MCoupon;
  7. use Mall\Framework\Core\ErrorCode;
  8. use Mall\Framework\Core\StatusCode;
  9. /**
  10. * Description: 收银台,订单计算提成
  11. * Class Cashier
  12. * @package JInDouYun\Controller\Cashier
  13. */
  14. class Cashier extends BaseController
  15. {
  16. /**
  17. * @var MCashier
  18. */
  19. private $objMCashier;
  20. /**
  21. * Cashier constructor.
  22. * @param bool $isCheckAcl
  23. * @param bool $isMustLogin
  24. * @param bool $checkToken
  25. * @param bool $getAreaCode
  26. * @throws \Exception
  27. */
  28. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
  29. {
  30. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
  31. $this->objMCashier = new MCashier($this->onlineUserId, $this->onlineEnterpriseId);
  32. }
  33. /**
  34. * Doc: (des="")
  35. * User: XMing
  36. * Date: 2020/9/2
  37. * Time: 12:13 下午
  38. * @throws \Exception
  39. */
  40. public function calculatePushMoney()
  41. {
  42. $params = $this->request->getRawJson();
  43. if (!isset($params['orderId'])) {
  44. parent::sendOutput('orderId参数错误', ErrorCode::$paramError);
  45. }
  46. $result = $this->objMCashier->calculatePushMoney($params['orderId']);
  47. if (!$result->isSuccess()) {
  48. parent::sendOutput($result->getData(), $result->getErrorCode());
  49. }
  50. parent::sendOutput($result->getData());
  51. }
  52. /**
  53. * Doc: (des="收银台统计")
  54. * User: XMing
  55. * Date: 2020/9/3
  56. * Time: 3:01 下午
  57. */
  58. public function overView()
  59. {
  60. $params = $this->request->getRawJson();
  61. if (empty($params)) {
  62. parent::sendOutput('参数为空', ErrorCode::$dberror);
  63. }
  64. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  65. $params['limit'] = $pageParams['limit'];
  66. $params['offset'] = $pageParams['offset'];
  67. $result = $this->objMCashier->overView($params);
  68. if (!$result->isSuccess()) {
  69. parent::sendOutput($result->getData(), $result->getErrorCode());
  70. }
  71. $returnData = $result->getData();
  72. $pageData = [
  73. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  74. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  75. 'pageTotal' => $returnData['total'],
  76. ];
  77. parent::sendOutput($returnData['data'], 0, $pageData);
  78. }
  79. /**
  80. * Doc: (des="根据手机号检索会员信息")
  81. * User: XMing
  82. * Date: 2020/9/11
  83. * Time: 2:23 下午
  84. * @throws \Exception
  85. */
  86. public function searchCustomerDetails()
  87. {
  88. $mobile = $this->request->param('mobile');
  89. if (empty($mobile)) {
  90. parent::sendOutput('mobile参数错误', ErrorCode::$paramError);
  91. }
  92. $result = $this->objMCashier->searchCustomerDetails($mobile);
  93. if (!$result->isSuccess()) {
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. parent::sendOutput($result->getData());
  97. }
  98. /**
  99. * 添加购物车,公共字段
  100. *
  101. * @return array
  102. */
  103. public function commonFieldFilter()
  104. {
  105. $params = $this->request->getRawJson();
  106. if (empty($params)) {
  107. parent::sendOutput('参数为空', ErrorCode::$paramError);
  108. }
  109. $cartData = [
  110. 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据
  111. ];
  112. foreach ($cartData as $key => $value) {
  113. if (empty($value) && $value !== 0) {
  114. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  115. }
  116. }
  117. $goodsData = [];
  118. foreach ($cartData['goodsData'] as $key => $val) {
  119. $goodsData[$key] = [
  120. 'goodsBasicId' => isset($val['goodsBasicId']) ? $val['goodsBasicId'] : '',
  121. 'goodsId' => isset($val['goodsId']) ? $val['goodsId'] : '',
  122. 'skuId' => isset($val['skuId']) ? $val['skuId'] : '',
  123. 'buyNum' => isset($val['buyNum']) ? $val['buyNum'] : '',
  124. 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
  125. 'source' => isset($val['source']) ? $val['source'] : '',
  126. 'warehouseId' => isset($val['warehouseId']) ? $val['warehouseId'] : '',
  127. ];
  128. foreach ($goodsData[$key] as $k => $v) {
  129. if (empty($v)) {
  130. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  131. }
  132. }
  133. $goodsData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $goodsData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
  134. }
  135. $cartData['goodsData'] = $goodsData;//过滤后数据
  136. return $cartData;
  137. }
  138. /**
  139. * Doc: (des="加入购物车")
  140. * User: XMing
  141. * Date: 2020/9/12
  142. * Time: 9:58 上午
  143. * @throws \Exception
  144. */
  145. public function addCart()
  146. {
  147. $userCenterId = $this->request->param('userCenterId');
  148. $warehouseId = $this->request->param('warehouseId');
  149. $cartData = $this->commonFieldFilter();
  150. if (empty($userCenterId)) {
  151. $userCenterId = StatusCode::$noneUserCenter;//
  152. }
  153. $result = false;
  154. $objMCashierCart = new MCashierCart($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId);
  155. foreach ($cartData['goodsData'] as $val){
  156. $result = $objMCashierCart->addCartApi(['goodsData' => [$val]]);
  157. }
  158. if ($result->isSuccess()) {
  159. parent::sendOutput($result->getData());
  160. }
  161. parent::sendOutput($result->getData(), $result->getErrorCode());
  162. }
  163. /**
  164. * 更新商品数量(购物车内操作)
  165. * @throws \Exception
  166. */
  167. public function updateBuyNum()
  168. {
  169. $userCenterId = $this->request->param('userCenterId');
  170. $cartId = $this->request->param('request_id');
  171. if (empty($cartId)) {
  172. parent::sendOutput('id参数错误', ErrorCode::$paramError);
  173. }
  174. $params = $this->request->getRawJson();
  175. $params['cartId'] = $cartId;
  176. if (empty($userCenterId)) {
  177. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  178. }
  179. $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
  180. $result = $objMCashierCart->updateBuyNumApi($params);
  181. if ($result->isSuccess()) {
  182. parent::sendOutput($result->getData());
  183. }
  184. parent::sendOutput($result->getData(), $result->getErrorCode());
  185. }
  186. /**
  187. * 删除购物车中商品(可批量)
  188. * @throws \Exception
  189. */
  190. public function delCart()
  191. {
  192. $userCenterId = $this->request->param('userCenterId');
  193. $params = $this->request->getRawJson();
  194. $paramsData = [
  195. 'id' => isset($params['cartId']) ? $params['cartId'] : 0,
  196. ];
  197. foreach ($paramsData as $key => $value) {
  198. if (empty($value) && $value !== 0) {
  199. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  200. }
  201. }
  202. if (empty($userCenterId)) {
  203. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  204. }
  205. $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
  206. $result = $objMCashierCart->delCart($paramsData);
  207. if ($result->isSuccess()) {
  208. parent::sendOutput($result->getData());
  209. }
  210. parent::sendOutput($result->getData(), $result->getErrorCode());
  211. }
  212. /**
  213. * 获取用户购物车数据
  214. * @throws \Exception
  215. */
  216. public function getCartByUserCenterId()
  217. {
  218. $userCenterId = $this->request->param('userCenterId');
  219. $userCouponId = $this->request->param('userCouponId');//优惠券id
  220. $params = $this->request->getRawJson();
  221. if (empty($userCenterId)) {
  222. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  223. }
  224. $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId, $this->onlineUserId);
  225. $isZero = isset($params['isZero']) && !empty($params['isZero']) ? $params['isZero'] : StatusCode::$delete;
  226. $result = $objMCashierCart->getCashierCartByUserCenterIdApi($isZero,$userCouponId);
  227. if ($result->isSuccess()) {
  228. $returnData = $result->getData();
  229. $pageData = [
  230. 'pageIndex' => 0,
  231. 'pageSize' => 0,
  232. 'pageTotal' => $returnData['total']
  233. ];
  234. parent::sendOutput($returnData['data'], 0, $pageData);
  235. }
  236. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  237. }
  238. /**
  239. * Doc: (des="")
  240. * User: XMing
  241. * Date: 2020/9/12
  242. * Time: 10:57 上午
  243. * @throws \Exception
  244. */
  245. public function clearCart()
  246. {
  247. $userCenterId = $this->request->param('userCenterId');
  248. if (empty($userCenterId)) {
  249. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  250. }
  251. $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
  252. $result = $objMCashierCart->clearCart();
  253. if ($result->isSuccess()) {
  254. parent::sendOutput($result->getData());
  255. }
  256. parent::sendOutput($result->getData(), $result->getErrorCode());
  257. }
  258. /**
  259. * Doc: (des="")
  260. * User: XMing
  261. * Date: 2020/9/11
  262. * Time: 6:09 下午
  263. */
  264. public function saveEntryData()
  265. {
  266. $params = $this->request->getRawJson();
  267. $data = [
  268. 'shopId' => isset($params['shopId']) ? $params['shopId'] : null,
  269. 'entryData' => isset($params['entryData']) ? json_encode($params['entryData']) : null,
  270. ];
  271. foreach ($data as $key => $val){
  272. if (empty($val)){
  273. parent::sendOutput($key.'参数错误',ErrorCode::$paramError);
  274. }
  275. }
  276. $result = $this->objMCashier->saveEntryData($data);
  277. if ($result->isSuccess()) {
  278. parent::sendOutput($result->getData());
  279. }
  280. parent::sendOutput($result->getData(), $result->getErrorCode());
  281. }
  282. /**
  283. * Doc: (des="获取挂单记录")
  284. * User: XMing
  285. * Date: 2020/9/12
  286. * Time: 6:20 下午
  287. */
  288. public function getAllEntryData()
  289. {
  290. $paramsData = $this->request->getRawJson();
  291. $params = [
  292. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  293. 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  294. 'shopId' => isset($paramsData['shopId']) ? $paramsData['shopId'] : null,
  295. ];
  296. foreach ($params as $key => $value) {
  297. if (empty($value) && $value !== 0) {
  298. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  299. }
  300. }
  301. $offset = ($params['page'] - 1) * $params['pageSize'];
  302. $selectParams = [
  303. 'limit' => $params['pageSize'],
  304. 'offset' => $offset,
  305. 'shopId' => $params['shopId']
  306. ];
  307. $dbResult = $this->objMCashier->getAllEntryData($selectParams);
  308. if ($dbResult->isSuccess()) {
  309. $returnData = $dbResult->getData();
  310. $pageData = [
  311. 'pageIndex' => $params['page'],
  312. 'pageSize' => $params['pageSize'],
  313. 'pageTotal' => $returnData['total'],
  314. ];
  315. parent::sendOutput($returnData['data'], 0, $pageData);
  316. }
  317. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  318. }
  319. /**
  320. * Doc: (des="取单")
  321. * User: XMing
  322. * Date: 2020/9/12
  323. * Time: 6:27 下午
  324. */
  325. public function getEntryData()
  326. {
  327. $id = $this->request->param('request_id');
  328. if (empty($id)){
  329. parent::sendOutput('id参数错误',ErrorCode::$paramError);
  330. }
  331. $dbResult = $this->objMCashier->getEntryData($id);
  332. if ($dbResult->isSuccess()) {
  333. parent::sendOutput($dbResult->getData());
  334. }
  335. parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
  336. }
  337. /**
  338. * Doc: (des="删除挂单")
  339. * User: XMing
  340. * Date: 2020/9/12
  341. * Time: 6:38 下午
  342. */
  343. public function delEntryData()
  344. {
  345. $id = $this->request->param('request_id');
  346. if (empty($id)){
  347. parent::sendOutput('id参数错误',ErrorCode::$paramError);
  348. }
  349. $dbResult = $this->objMCashier->delEntryData($id);
  350. if ($dbResult->isSuccess()) {
  351. parent::sendOutput($dbResult->getData());
  352. }
  353. parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
  354. }
  355. /**
  356. * Doc: (des="收银台修改商品价格")
  357. * User: XMing
  358. * Date: 2020/9/14
  359. * Time: 9:24 上午
  360. */
  361. public function changePrice()
  362. {
  363. $userCenterId = $this->request->param('userCenterId');
  364. if (empty($userCenterId)) {
  365. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  366. }
  367. $params = $this->request->getRawJson();
  368. $data = [
  369. 'goodsId'=>isset($params['goodsId']) ? $params['goodsId'] : null,
  370. 'skuId' => isset($params['skuId']) ? $params['skuId'] : null,
  371. 'changePrice' => isset($params['changePrice']) ? $params['changePrice'] : null,
  372. 'customerUid' => $userCenterId,
  373. ];
  374. foreach ($data as $key => $val){
  375. if (empty($val)){
  376. parent::sendOutput($key.'参数错误',ErrorCode::$paramError);
  377. }
  378. }
  379. $dbResult = $this->objMCashier->changePrice($data);
  380. if ($dbResult->isSuccess()) {
  381. parent::sendOutput($dbResult->getData());
  382. }
  383. parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
  384. }
  385. /**
  386. * Doc: (des="收银台营销活动")
  387. * User: XMing
  388. * Date: 2020/9/14
  389. * Time: 2:26 下午
  390. * @throws \Exception
  391. */
  392. public function activityAll()
  393. {
  394. $userCenterId = $this->request->param('userCenterId');
  395. if (empty($userCenterId)) {
  396. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  397. }
  398. $paramsData = $this->request->getRawJson();
  399. $pageParams = pageToOffset(isset($paramsData['page']) ? $paramsData['page'] : 1, isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10);
  400. $params['limit'] = $pageParams['limit'];
  401. $params['offset'] = $pageParams['offset'];
  402. $params['type'] = StatusCode::$standard;
  403. $objMCoupon = new MCoupon($userCenterId,$this->onlineEnterpriseId);
  404. $result = $objMCoupon->selectAll($params);
  405. if ($result->isSuccess()) {
  406. $returnData = $result->getData();
  407. $pageData = [
  408. 'pageIndex' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  409. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  410. 'pageTotal' => $returnData['total'],
  411. ];
  412. parent::sendOutput($returnData['data'], 0, $pageData);
  413. }
  414. parent::sendOutput($result->getData(), $result->getErrorCode());
  415. }
  416. }