request->isAjax) { if (\Yii::$app->request->isGet) { $store = Store::findOne(['id' => $this->store_id]); $data['store_id'] = $store['id']; $data['scan_code_bind'] = $store['scan_code_bind']; $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.'/#/plugins2/Store/pay/cashRegister?store_id='.$store['id'].'&sign='.$sign; $data['scan_code_bind'] = $store['scan_code_bind']; $extra = StoreCashierExtra::findOne([ 'store_id' => $this->store_id, 'status' => 1, ]); $store_setting = StoreSettings::findOne([ 'store_id' => $this->store_id, 'status' => 1, ]); if($extra){ $score_give_setting = json_decode($extra['score_give_setting'],true); $score_deduct_setting = json_decode($extra['score_deduct_setting'],true); $data['score_give_setting'] = $score_give_setting?$score_give_setting:''; $data['score_deduct_setting'] = $score_deduct_setting?$score_deduct_setting:''; $data['preferential_deduction'] = $extra['preferential_deduction']; $data['preferential_gift'] = $extra['preferential_gift']; } $data['is_preferential_gift'] = $store_setting['is_preferential_gift']??0; return $this->success('ok', $data); } else { $params = \Yii::$app->request->post('form'); $params['mall_id'] = $this->mall_id; $params['id'] = $this->store_id; $res = Store::setData($params); if ($res == false) return $this->error(Store::getStaticError()); $params['score_give_setting'] = json_encode($params['score_give_setting']); $params['score_deduct_setting'] = json_encode($params['score_deduct_setting']); $params['currency_deduct_setting'] = json_encode([]); $params['member_price_setting'] = json_encode([]); $params['member_buy_limit_setting'] = json_encode([]); $res = StoreCashierExtra::setData($this->store_id,$params); if ($res == false) return $this->error(StoreCashierExtra::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']; $params['limit'] = $params['limit'] ?? $this->pageSize; $page_data = StoreCashierOrder::listPage($params); if ($page_data === false) return $this->error(StoreWithdrawLog::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'] = StoreCashierOrder::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 = 'o2o门店收银台订单列表-' . date('YmdHis') . '_' . rand(10000, 99999); $model = StoreCashierOrder::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 = StoreCashierOrder::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 actionCommissionAndScoreList(){ $params = \Yii::$app->request->get(); $wallet_type = 'commission'; if(!empty($params['wallet_type'])) $wallet_type = $params['wallet_type']; $condition = [ 'where'=>[ ['source_table' => ['store_cashier_order',StoreCashierOrder::tableName(),'store_cashier_order_detail']], ['source_table_id'=>$params['order_id']] ], ]; CapitalLog::$capitalType = "{$wallet_type}"; $list = CapitalLog::getList($condition,0); $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all(); $level_data = array_column($level,'name','level'); CapitalLog::$capitalType = "{$wallet_type}_frozen"; $condition['where'][] = ['status'=>0]; $frozen_list = CapitalLog::getList($condition,1); $list = array_merge($list,$frozen_list); return $this->success('操作成功',['list'=>$list,'user_level'=>$level_data]); } public function actionGetCouponList(){ $params = \Yii::$app->request->get(); $type = $params['type']??2; $store_id = $this->store_id; $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COUPON); $coupon_list = []; if($is_install){ $coupon_list = AddonsCoupon::lists([ 'where'=>[ new Expression("FIND_IN_SET({$store_id},store_id)"), ['mall_id'=>$this->mall_id], ['type'=>$type], ['status'=>StatusEnum::ENABLED], ['coupon_status'=>AddonsCouponEnum::STATUS_RECEIVING], ], 'select'=>'id,name' ]); } return $this->success('ok', ['coupon_list'=>$coupon_list]); } 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 = Store::findOne(['mall_id'=>$this->mall_id,'id'=>$this->store_id]); if(empty($store)) return $this->error('店铺不存在'); $model = StoreMiniCode::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 = 'plugins2/Store/store/index'; }else{ $page = '/plugins2/Store/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 = StoreMiniCode::setData($params); } $applet_url = $model['applet_code']; $this->success('获取成功',['applet_url'=>$applet_url]); } } } }