123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- <?php
- namespace JInDouYun\Controller\Cashier;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Cashier\MCashier;
- use JinDouYun\Model\Cashier\MCashierCart;
- use JinDouYun\Model\Market\MCoupon;
- use JinDouYun\Model\Enterprise\MEnterprise;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- /**
- * Description: 收银台,订单计算提成
- * Class Cashier
- * @package JInDouYun\Controller\Cashier
- */
- class Cashier extends BaseController
- {
- /**
- * @var MCashier
- */
- private $objMCashier;
- private $objMEnterprise;
-
- /**
- * Cashier constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @param bool $checkToken
- * @param bool $getAreaCode
- * @throws \Exception
- */
- public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
- $this->objMCashier = new MCashier($this->onlineUserId, $this->onlineEnterpriseId);
- $this->objMEnterprise = new MEnterprise();
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/9/2
- * Time: 12:13 下午
- * @throws \Exception
- */
- public function calculatePushMoney()
- {
- $params = $this->request->getRawJson();
- if (!isset($params['orderId'])) {
- parent::sendOutput('orderId参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMCashier->calculatePushMoney($params['orderId']);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="收银台统计")
- * User: XMing
- * Date: 2020/9/3
- * Time: 3:01 下午
- */
- public function overView()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$dberror);
- }
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $result = $this->objMCashier->overView($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * Doc: (des="根据手机号检索会员信息")
- * User: XMing
- * Date: 2020/9/11
- * Time: 2:23 下午
- * @throws \Exception
- */
- public function searchCustomerDetails()
- {
- $mobile = $this->request->param('mobile');
- if (empty($mobile)) {
- parent::sendOutput('mobile参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMCashier->searchCustomerDetails($mobile);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
-
- /**
- * Doc: (des="获取通用收银客户信息")
- * User: XMing
- * Date: 2020/9/11
- * Time: 2:23 下午
- * @throws \Exception
- */
- public function getCommonCustomerInfo()
- {
- if(empty($this->onlineEnterpriseId)){
- parent::sendOutput('企业信息不存在', ErrorCode::$paramError);
- }
- $params['enterpriseId'] = $this->onlineEnterpriseId;
-
- $result = $this->objMEnterprise->getEnterpriseInfo($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- $data = $result->getData();
- if(empty($data )){
- parent::sendOutput('企业信息不存在', ErrorCode::$paramError);
- }
- // $mobile = $data["commonCashierCustomerMobile"];
- $mobile = "13600000001";
- $result = $this->objMCashier->searchCustomerDetails($mobile);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 添加购物车,公共字段
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $cartData = [
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据
- ];
- foreach ($cartData as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $goodsData = [];
- foreach ($cartData['goodsData'] as $key => $val) {
- $goodsData[$key] = [
- 'goodsBasicId' => isset($val['goodsBasicId']) ? $val['goodsBasicId'] : '',
- 'goodsId' => isset($val['goodsId']) ? $val['goodsId'] : '',
- 'skuId' => isset($val['skuId']) ? $val['skuId'] : '',
- 'buyNum' => isset($val['buyNum']) ? $val['buyNum'] : '',
- 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
- 'source' => isset($val['source']) ? $val['source'] : '',
- 'warehouseId' => isset($val['warehouseId']) ? $val['warehouseId'] : '',
- ];
- foreach ($goodsData[$key] as $k => $v) {
- if (empty($v)) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- $goodsData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $goodsData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
- }
- $cartData['goodsData'] = $goodsData;//过滤后数据
- return $cartData;
- }
- /**
- * Doc: (des="加入购物车")
- * User: XMing
- * Date: 2020/9/12
- * Time: 9:58 上午
- * @throws \Exception
- */
- public function addCart()
- {
- $userCenterId = $this->request->param('userCenterId');
- $warehouseId = $this->request->param('warehouseId');
- $cartData = $this->commonFieldFilter();
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//
- }
- $result = false;
- $objMCashierCart = new MCashierCart($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId);
- foreach ($cartData['goodsData'] as $val){
- $result = $objMCashierCart->addCartApi(['goodsData' => [$val]]);
- }
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 更新商品数量(购物车内操作)
- * @throws \Exception
- */
- public function updateBuyNum()
- {
- $userCenterId = $this->request->param('userCenterId');
- $cartId = $this->request->param('request_id');
- if (empty($cartId)) {
- parent::sendOutput('id参数错误', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- $params['cartId'] = $cartId;
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
- $result = $objMCashierCart->updateBuyNumApi($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 删除购物车中商品(可批量)
- * @throws \Exception
- */
- public function delCart()
- {
- $userCenterId = $this->request->param('userCenterId');
- $params = $this->request->getRawJson();
- $paramsData = [
- 'id' => isset($params['cartId']) ? $params['cartId'] : 0,
- ];
- foreach ($paramsData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
- $result = $objMCashierCart->delCart($paramsData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取用户购物车数据
- * @throws \Exception
- */
- public function getCartByUserCenterId()
- {
- $userCenterId = $this->request->param('userCenterId');
- $userCouponId = $this->request->param('userCouponId');//优惠券id
- $params = $this->request->getRawJson();
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId, $this->onlineUserId);
- $isZero = isset($params['isZero']) && !empty($params['isZero']) ? $params['isZero'] : StatusCode::$delete;
- $result = $objMCashierCart->getCashierCartByUserCenterIdApi($isZero,$userCouponId);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => 0,
- 'pageSize' => 0,
- 'pageTotal' => $returnData['total']
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/9/12
- * Time: 10:57 上午
- * @throws \Exception
- */
- public function clearCart()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMCashierCart = new MCashierCart($userCenterId, $this->onlineEnterpriseId,$this->onlineUserId);
- $result = $objMCashierCart->clearCart();
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/9/11
- * Time: 6:09 下午
- */
- public function saveEntryData()
- {
- $params = $this->request->getRawJson();
- $data = [
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : null,
- 'entryData' => isset($params['entryData']) ? json_encode($params['entryData']) : null,
- ];
- foreach ($data as $key => $val){
- if (empty($val)){
- parent::sendOutput($key.'参数错误',ErrorCode::$paramError);
- }
- }
- $result = $this->objMCashier->saveEntryData($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="获取挂单记录")
- * User: XMing
- * Date: 2020/9/12
- * Time: 6:20 下午
- */
- public function getAllEntryData()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
- 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
- 'shopId' => isset($paramsData['shopId']) ? $paramsData['shopId'] : null,
- ];
- foreach ($params as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $offset = ($params['page'] - 1) * $params['pageSize'];
- $selectParams = [
- 'limit' => $params['pageSize'],
- 'offset' => $offset,
- 'shopId' => $params['shopId']
- ];
- $dbResult = $this->objMCashier->getAllEntryData($selectParams);
- if ($dbResult->isSuccess()) {
- $returnData = $dbResult->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
- }
- /**
- * Doc: (des="取单")
- * User: XMing
- * Date: 2020/9/12
- * Time: 6:27 下午
- */
- public function getEntryData()
- {
- $id = $this->request->param('request_id');
- if (empty($id)){
- parent::sendOutput('id参数错误',ErrorCode::$paramError);
- }
- $dbResult = $this->objMCashier->getEntryData($id);
- if ($dbResult->isSuccess()) {
- parent::sendOutput($dbResult->getData());
- }
- parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
- }
- /**
- * Doc: (des="删除挂单")
- * User: XMing
- * Date: 2020/9/12
- * Time: 6:38 下午
- */
- public function delEntryData()
- {
- $id = $this->request->param('request_id');
- if (empty($id)){
- parent::sendOutput('id参数错误',ErrorCode::$paramError);
- }
- $dbResult = $this->objMCashier->delEntryData($id);
- if ($dbResult->isSuccess()) {
- parent::sendOutput($dbResult->getData());
- }
- parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
- }
- /**
- * Doc: (des="收银台修改商品价格")
- * User: XMing
- * Date: 2020/9/14
- * Time: 9:24 上午
- */
- public function changePrice()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $params = $this->request->getRawJson();
- $data = [
- 'goodsId'=>isset($params['goodsId']) ? $params['goodsId'] : null,
- 'skuId' => isset($params['skuId']) ? $params['skuId'] : null,
- 'changePrice' => isset($params['changePrice']) ? $params['changePrice'] : null,
- 'customerUid' => $userCenterId,
- ];
- foreach ($data as $key => $val){
- if (empty($val)){
- parent::sendOutput($key.'参数错误',ErrorCode::$paramError);
- }
- }
- $dbResult = $this->objMCashier->changePrice($data);
- if ($dbResult->isSuccess()) {
- parent::sendOutput($dbResult->getData());
- }
- parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
- }
- /**
- * Doc: (des="收银台营销活动")
- * User: XMing
- * Date: 2020/9/14
- * Time: 2:26 下午
- * @throws \Exception
- */
- public function activityAll()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)) {
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $paramsData = $this->request->getRawJson();
- $pageParams = pageToOffset(isset($paramsData['page']) ? $paramsData['page'] : 1, isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['type'] = StatusCode::$standard;
- $objMCoupon = new MCoupon($userCenterId,$this->onlineEnterpriseId);
- $result = $objMCoupon->selectAll($params);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($paramsData['page']) ? $paramsData['page'] : 1,
- 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|