Cashier.Class.php 17 KB

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