request->isAjax) { if (\Yii::$app->request->isGet) { $store = HappinessStore::findOne(['id' => $this->store_id]); $data['store_id'] = $store['id']; $data['export_url'] = \Yii::$app->request->hostInfo . '?r=store/client/cash/cashier-log'; $H5Url = MallHost::getHost($this->mall_id,'h5_url'); $sign = $this->mall['mall_sign']??''; $data['cashier_url'] = $H5Url.'/#/customDesigns/Happiness/pay/cashRegister?store_id='.$store['id'].'&sign=' .$sign; return $this->success('ok', $data); } else { $params = \Yii::$app->request->post('form'); $params['mall_id'] = $this->mall_id; $params['id'] = $this->store_id; $res = HappinessStore::setData($params); if ($res == false) return $this->error(HappinessStore::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } public function actionCashierLog() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $params = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; $where[] = ['pay_status' => 1]; $where[] = ['status' => StatusEnum::ENABLED]; if (!empty($params['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [ 'or', ['like', 'username', $params['keyword']], ['like', 'nickname', $params['keyword']], ]], 'select' => 'id']); $user_ids = array_column($user_list, 'id'); $where[] = ['in', 'user_id', $user_ids]; } if (!empty($params['start'])) $where[] = ['>=', 'pay_time', strtotime($params['start'])]; if (!empty($params['end'])) $where[] = ['<=', 'pay_time', strtotime($params['end'])]; if (!empty($params['min'])) $where[] = ['>=', 'pay_money', $params['min']]; if (!empty($params['max'])) $where[] = ['<=', 'pay_money', $params['max']]; $params['where'] = $where; $params['order'] = 'id desc'; $params['with'] = ['user','detail']; $params['limit'] = $params['limit'] ?? $this->pageSize; $page_data = HappinessCashierOrder::listPage($params); if ($page_data === false) return $this->error(HappinessCashierOrder::getStaticError()); if (!empty($page_data['list'])) { foreach ($page_data['list'] as &$item) { $extra = json_decode($item['extra'], true); $item['extra'] = ''; $item['commission'] = 0; if ($extra) { $is_score_deduct = 0; $discount_money = 0; foreach ($extra as $k => $v) { if ($v) { switch ($k) { case "member_deduct_money": $item['extra'] .= '会员价优惠:' . $v; break; case "deduct_num_score": $is_score_deduct = 1; break; case "discount_money": $discount_money = $v; // $item['extra'] .= ' 优惠:' . $v; break; case "agent_commission": $item['commission']+=$v; // $item['extra'] .= ' 渠道分红:' . $v; break; case "distribution_commission": //case "boss_commission": case "store_boss_commission": $item['commission']+=$v; // $item['extra'] .= ' 分销分红:' . $v; break; case "area_commission": $item['commission'] += $v; // $item['extra'] .= ' 区域分红:' . $v; break; case "double_copy_commission": $item['commission'] += $v; break; } } } if($is_score_deduct){ $item['extra'] .= ',积分抵扣优惠:' . $discount_money; }else{ $item['extra'] .= ',优惠券优惠:' . $discount_money; } $item['extra'] = trim($item['extra'] ,','); $item['commission'] = bcadd($item['commission'],0,2); } } } $page_data['export_list'] = HappinessCashierOrder::fieldsList(); return $this->success('ok', $page_data); } } if (\Yii::$app->request->post('flag') == 'EXPORT') { $params = \Yii::$app->request->post(); $params['mall_id'] = $this->mall_id; $params['store_id'] = $this->store_id; $filename = '幸福小店收银台订单列表-' . date('YmdHis') . '_' . rand(10000, 99999); $model = HappinessCashierOrder::find(); $model->where(['mall_id' => $params['mall_id']]); $model->andWhere(['store_id' => $params['store_id']]); $model->andWhere(['pay_status' => 1]); if (!empty($params['start'])) $model->andWhere(['>=', 'pay_time', strtotime($params['start'])]); if (!empty($params['end'])) $model->andWhere(['<=', 'pay_time', strtotime($params['end'])]); if (!empty($params['min'])) $model->andWhere(['>=', 'pay_money', $params['min']]); if (!empty($params['max'])) $model->andWhere(['<=', 'pay_money', $params['max']]); if (!empty($params['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $params['mall_id']], [ 'or', ['like', 'username', $params['keyword']], ['like', 'nickname', $params['keyword']], ]], 'select' => 'id']); $user_ids = array_column($user_list, 'id'); $model->andWhere(['in', 'user_id', $user_ids]); } $model->with(['user']); $fields = $params['fields']; $fields = explode(',',$fields); $fields_arr = HappinessCashierOrder::fieldsList(); $have_select_field_arr = []; foreach ($fields as $value) { $have_select_field_arr[] = $fields_arr[$value]; } $csv = new CsvTool(); $csv->filename = $filename; $csv->export_mode = CsvTool::EXPORT_MODE_SYNC; $csv->header = $have_select_field_arr; $orders = $model->all(); empty($csv->header) && $csv->header = array_keys($orders[0]); $data = []; foreach ($orders as $order){ $row = []; foreach ($fields as $field) { if ($field == 'nickname') { $row[] = $order['user']['nickname']; } else if ($field == 'extra') { $extra = json_decode($order['extra'], true); $extra_content = ''; $is_score_deduct = 0; $discount_money = 0; if ($extra) { foreach ($extra as $k => $v) { if ($v) { switch ($k) { case "member_deduct_money": $extra_content .= ',会员价优惠:' . $v; break; case "deduct_num_score": $is_score_deduct = 1; break; case "discount_money": $discount_money = $v; // $extra_content .= ' 优惠:' . $v; break; case "agent_commission": $extra_content .= ',渠道分红:' . $v; break; case "distribution_commission": $extra_content .= ',分销分红:' . $v; break; case "boss_commission": $extra_content .= ',股东分红:' . $v; break; case "store_boss_commission": $extra_content .= ',门店股东分红:' . $v; break; } } } if($is_score_deduct){ $extra_content .= ',积分抵扣优惠:' . $discount_money; }else{ $extra_content .= ',优惠券优惠:' . $discount_money; } } $row[] = trim($extra_content,','); } else if ($field == 'pay_time') { $row[] = !empty($order['pay_time']) ? date('Y-m-d H:i:s', $order['pay_time']) : ''; } else { if ((isset($order[$field]))) $row[] = $order[$field]; } } $data[]=$row; } $csv->data = $data; $csv->export(); } } public function actionShowMiniPromotionCode(){ $request = \Yii::$app->request; if ($request->isAjax) { if ($request->isPost) { $params = \Yii::$app->request->post(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($params,[ [['type'], 'required'], ]); if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $store = HappinessStore::findOne(['mall_id'=>$this->mall_id,'id'=>$this->store_id]); if(empty($store)) return $this->error('店铺不存在'); $model = HappinessStoreMiniCode::findOne(['store_id'=>$store['id'],'mall_id'=>$this->mall_id,'type'=>$params['type']]); if(empty($model)){ $mall = $this->mall; $content = [ 'mall_id'=>$this->mall_id, 'store_id'=>$store['id'], 'mall_sign'=>$mall['mall_sign'], 'type'=>$params['type'], ]; $content = json_encode($content); if($params['type']==1){ $page = 'customDesigns/Happiness/shopPagesUI'; }else{ $page = '/customDesigns/Happiness/pay/cashRegister'; } $code = md5($content); $obj = new MiniQrCode(); $applet_code = $obj->getAppletQrCode($this->mall_id,$page,$code); $params['mall_id'] = $this->mall_id; $params['code'] = $code; $params['store_id'] = $store['id']; $params['content'] = $content; $params['applet_code'] = $applet_code; $model = HappinessStoreMiniCode::setData($params); } $applet_url = $model['applet_code']; $this->success('获取成功',['applet_url'=>$applet_url]); } } } public function actionSearchGoodsData() { $request = Yii::$app->request; try { if ($request->isAjax && $request->isGet) { $get = $request->get(); $res = Yii::$app->services->validate->validate($get, [ [['keyword','label_id'], 'string'], ]); if (!$res) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $info = (new GoodsService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->searchStoreGoodsData($get); //获取标签 $goods_label= \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic.goods_label'); $goods_label = empty($goods_label) ? [] : json_decode($goods_label,true); $goods_label_name=array_column($goods_label,null,'level'); if(!empty($info['list'])) { $newList=[]; foreach ($info['list'] as $item) { $oData=$item; unset($oData['yunAttr']); $oData['cats']=$oData['yunGoods']['cats']; unset($oData['yunGoods']); foreach ($item['yunAttr'] as $attr) { $newItem['cats']=$oData['cats']; $newItem['goods_id']=$attr['goods_id']; $newItem['id']=$attr['attr_id']; $newItem['goods_name']=$oData['goods_name'].'-'.$attr['attr']['name']; $newItem['price']=$attr['attr']['price']; $newItem['stock']=$attr['stock']; $newItem['cover_pic']=!empty($attr['attr']['pic_url']) ?$attr['attr']['pic_url']:$item['cover_pic']; $newItem['buy_num']=1; $newItem['max_income']=bcmul($attr['price'],bcdiv($item['store_scale'],100,4),2); $newItem['label_name']=isset($goods_label_name[$item['label_id']])?$goods_label_name[$item['label_id']]['name']:''; $newList[]=$newItem; } } $info['list']=$newList; } if(!empty($goods_label)) { foreach ($goods_label as &$item) { $item['name']=$item['name'].'('.$item['income_start'].'%-'.$item['income_end'].'%)'; } } $info['goods_label']=$goods_label; return $this->success('获取成功', $info); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function actionConfirmGoods() { $request = Yii::$app->request; try { if ($request->isAjax && $request->isPost) { $post = $request->post(); //获得商品 $id=$post['order_id']; $goods_list=$post['goods_list']; if(empty($id)) { return $this->error('请选择订单'); } if(empty($goods_list)) { return $this->error('请选择商品'); } $order=HappinessCashierOrder::findOne(['id'=>$id,'mall_id'=>$this->mall_id,'store_id'=>$this->store_id]); if(empty($order)) { return $this->error('订单不存在'); } if($order['pay_status']!=StatusEnum::ENABLED) { return $this->error('订单未支付'); } //扣除商品库存和返还提货券 $casherService=new CashierService(); $res=$casherService->createDetail($id,$goods_list); if(!$res) { return $this->error($casherService->getError()); } $res=$casherService->settle($id); if(!$res) { return $this->error($casherService->getError()); } return $this->success('操作成功'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } }