Cashier.Class.php 17 KB

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