| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\cashier;
- use app\models\Address;
- use app\models\CashierActionLog;
- use app\models\CashierGoodsPriceLog;
- use app\models\District;
- use app\models\Goods;
- use app\models\Order;
- use app\models\SaasUser;
- use app\models\User;
- use app\models\UserLabel;
- use app\modules\admin\controllers\BaseController;
- use app\modules\admin\models\cashier\CashierUserForm;
- use app\modules\admin\models\cashier\HangingOrderForm;
- use app\modules\admin\models\order\MchOrderPayDataForm;
- use app\modules\admin\models\order\MchOrderSubmitForm;
- use app\modules\admin\models\order\MchOrderSubmitPreviewForm;
- use app\modules\admin\models\cashier\GoodsAttrInfoForm;
- use app\modules\admin\models\cashier\GoodsForm;
- use app\modules\admin\models\cashier\OrderListForm;
- use app\modules\admin\models\order\ReuseOrderGoodsPriceForm;
- use app\modules\admin\models\UserForm;
- class CashierIndexController extends BaseController
- {
- /**
- * 收银台添加用户
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/5 10:16
- */
- public function actionUserAdd(){
- $param = post_params();
- $form = new CashierUserForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->cashierUserAdd();
- return $this->asJson($res);
- }
- /**
- * 搜索用户
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/6 15:50
- */
- public function actionSearchUser(){
- $keyword = get_params('keyword');
- if(empty($keyword)){
- return $this->asJson(['code' => 0,'data'=>[]]);
- }
- if(substr($keyword, 0, 2) == '00'){
- $keyword *= 1;
- $data = ['id' => $keyword, 'store_id' => get_store_id()];
- } else {
- $data = ['AND', ['or',['like','binding',$keyword],['like','nickname',$keyword]], ['store_id' => get_store_id()]];
- }
- $userList = User::find()->where($data)->orderBy('created_at DESC')->select('id,nickname,binding, user_label_id')->asArray()->all();
- foreach ($userList as &$userItem) {
- $userLabel = UserLabel::getLabel(get_store_id(), $userItem['user_label_id']);
- $userItem['user_label_name'] = $userLabel->label_name ?: '';
- }
- return $this->asJson(['code'=>0,'data'=>$userList]);
- }
- //获取对应商品的规格信息
- public function actionGetGoodsAttr(){
- $form = new GoodsForm();
- $form->attributes = get_params();
- $form->user_id = get_params('user_id',0);
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 获取规格详情
- * @return mixed
- */
- public function actionGoodsAttrInfo()
- {
- $form = new GoodsAttrInfoForm();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 申请挂单
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/5 15:06
- */
- public function actionHangingOrder(){
- // 需要用户ID 挂单上皮ID
- $param = post_params();
- $form = new HangingOrderForm();
- $form->user_id = $param['user_id'];
- $form->store_id = get_store_id();
- $form->md_id = get_md_id();
- $form->goods_list = json_decode($param['goods_list'],true);
- $form->id = $param['id'] ?? 0;
- $res = $form->hangingOrder();
- return $this->asJson($res);
- }
- /**
- * 获取挂单列表 可查询指定用户的挂单信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/6 09:29
- */
- public function actionGetHangingOrderList(){
- $form = new HangingOrderForm();
- $form->user_id = get_params('user_id',0);
- $form->order_no = get_params('order_no','');
- $form->dateStart = get_params('dateStart','');
- $form->dateEnd = get_params('dateEnd','');
- $form->store_id = get_store_id();
- $form->md_id = get_md_id();
- $res = $form->getList();
- return $this->asJson($res);
- }
- // 获取挂单订单商品
- public function actionGetHangingOrderDetail(){
- $form = new HangingOrderForm();
- $form->goods_name = get_params('goods_name','');
- $form->id = get_params('id');
- $res = $form->getOrderDetail();
- return $this->asJson($res);
- }
- /**
- * 删除挂单订单
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/6 09:36
- */
- public function actionDelHangingOrder(){
- $form = new HangingOrderForm();
- $form->id = get_params('id');
- $res = $form->delHanging();
- return $this->asJson($res);
- }
- /**
- * 删除挂单订单商品
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/6 14:16
- */
- public function actionDelHangingOrderDetail(){
- $form = new HangingOrderForm();
- $form->id = get_params('id');
- $res = $form->delHangingOrderDetail();
- return $this->asJson($res);
- }
- /**
- * 取出挂单
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2022/12/6 14:47
- */
- public function actionGetHangingOrder(){
- $form = new HangingOrderForm();
- $form->id = post_params('id');
- $res = $form->getHangingOrder();
- return $this->asJson($res);
- }
- //结算预览
- public function actionOrderPreview(){
- $form = new MchOrderSubmitPreviewForm();
- $form->attributes = post_params();
- $form->user_id = post_params('user_id');
- $form->store_id = get_store_id();
- $form->md_id = get_md_id();
- return $this->asJson($form->search());
- }
- // todo 生成待支付订单
- public function actionSubmitOrder(){
- $form = new MchOrderSubmitForm();
- $form->attributes = post_params();
- $form->user_id = post_params('user_id');
- $form->store_id = get_store_id();
- $form->md_id = get_md_id();
- // $form->is_offline = 1;
- return $this->asJson($form->save());
- }
- // todo 支付订单
- public function actionPayData(){
- $form = new MchOrderPayDataForm();
- $form->attributes = post_params();
- $form->user_id = post_params('user_id');
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- //订单列表
- public function actionOrderList(){
- $store_id = get_store_id();
- $md_id = get_md_id();
- $form = new OrderListForm();
- $form->attributes = get_params();
- $form->is_offline = Order::IS_OFFLINE_FALSE;
- $form->store_id = $store_id;
- $form->md_id = $md_id;
- //$form->order_id = get_params('order_id');
- return $this->asJson($form->search());
- }
- public function actionOrderRefund(){
- // 获取订单
- $store_id = get_store_id();
- $form = new OrderListForm();
- $form->attributes = get_params();
- $form->is_offline = Order::IS_OFFLINE_FALSE;
- $form->store_id = $store_id;
- $form->order_id = get_params('order_id');
- return $this->asJson($form->orderRefund());
- }
- public function actionAddAddress() {
- $form = new UserForm();
- $form->attributes = post_params();
- $form->is_default = post_params('is_default', 0);
- $form->store_id = get_store_id();
- return $this->asJson($form->addAddress());
- }
- //修改购物车商品价格
- public function actionSetGoodsPrice() {
- try {
- $goods_id = post_params('goods_id');
- $attr_ = post_params('attr');
- $price = post_params('price');
- $user_id = post_params('user_id');
- $md_id = post_params('md_id');
- if (!$price || !$attr_) {
- throw new \Exception('修改价格失败,缺少规格或价格参数');
- }
- $goods = Goods::findOne($goods_id);
- if ($goods) {
- $attr = json_decode($attr_, true);
- $attr_id = array_column($attr['attr_list'], 'attr_id');
- sort($attr_id);
- $open = false;
- $goods_attr = json_decode($goods->attr, true);
- foreach ($goods_attr as &$attr_item) {
- $gods_attr_id = array_column($attr_item['attr_list'], 'attr_id');
- sort($gods_attr_id);
- if (!array_diff($gods_attr_id, $attr_id)) {
- $open = true;
- }
- }
- if ($open) {
- $goods_price_log = new CashierGoodsPriceLog();
- $goods_price_log->goods_id = $goods_id;
- $goods_price_log->attr = $attr_;
- $goods_price_log->price = $price;
- $goods_price_log->user_id = $user_id;
- $goods_price_log->md_id = $md_id;
- if (!$goods_price_log->save()) {
- throw new \Exception(json_encode($goods_price_log->errors, JSON_UNESCAPED_UNICODE));
- }
- } else {
- throw new \Exception('修改价格失败,商品规格信息查询失败');
- }
- } else {
- throw new \Exception('修改价格失败,商品信息未找到');
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '设置成功'
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionGetActionType(){
- $result = CashierActionLog::TEXT;
- $result[0] = '全部';
- return $this->asJson(['code' => 0,'data' => $result]);
- }
- public function actionGetActionLog()
- {
- $keyword = get_params('keyword');
- $actionType = get_params('action_type');
- $startTime = get_params('start_time');
- $endTime = get_params('end_time');
- $query = CashierActionLog::find()->alias('cal')->leftJoin(['u' => User::tableName()],'cal.user_id=u.id')->leftJoin(['su' => SaasUser::tableName()],'u.binding=su.mobile')->where(['cal.store_id' => get_store_id(), 'md_id' => get_md_id()]);
- if(!empty($keyword)){
- $query->andWhere(['like','su.name',$keyword]);
- }
- if($actionType > 0){
- $query->andWhere(['cal.action' => $actionType]);
- }
- if(!empty($startTime)){
- $query->andWhere(['>','cal.created_at',$startTime]);
- }
- if(!empty($endTime)){
- $query->andWhere(['<','cal.created_at',$endTime]);
- }
- $query->orderBy('cal.created_at DESC')->select('cal.*,su.name,su.avatar,su.mobile');
- $result = pagination_make($query,true);
- foreach($result['list'] as &$item){
- $item['created_at'] = date('Y-m-d H:i:s',$item['created_at']);
- $item['action_text'] = CashierActionLog::TEXT[$item['action']];
- }
- return $this->asJson(['code' => 0,'data' => $result]);
- }
- public function actionGetReuseGoodsPrice(){
- $form = new ReuseOrderGoodsPriceForm();
- $form->user_id = post_params('user_id');
- $form->goods_id = post_params('goods_id');
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- }
|