Cashier.Class.php 17 KB

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