| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace backendApi\modules\v1\controllers;
- use backendApi\modules\v1\models\Admin;
- use backendApi\modules\v1\models\exportForms\OrderExportForm;
- use backendApi\modules\v1\models\exportForms\ShopExportForm;
- use backendApi\modules\v1\models\lists\shop\DecOrderList;
- use backendApi\modules\v1\models\lists\shop\GoodsList;
- use backendApi\modules\v1\models\lists\shop\OrderDecList;
- use backendApi\modules\v1\models\lists\shop\OrderList;
- use backendApi\modules\v1\models\lists\shop\OrderPeriodAdjustList;
- use backendApi\modules\v1\models\lists\shop\OrderShopList;
- use backendApi\modules\v1\models\lists\shop\OrderStandardList;
- use backendApi\modules\v1\models\lists\shop\PackageList;
- use common\helpers\bonus\CalcCache;
- use backendApi\modules\v1\models\lists\shop\RemainPvList;
- use backendApi\modules\v1\models\lists\shop\FlowRemainPvList;
- use common\helpers\Cache;
- use common\helpers\Date;
- use common\helpers\Form;
- use common\helpers\Log;
- use common\helpers\snowflake\SnowFake;
- use common\libs\export\module\ShopExport;
- use common\models\DeclarationPackage;
- use common\models\DecOrder;
- use common\models\ExcelOrderShop;
- use common\models\FlowExchangePoints;
- use common\models\FlowReconsumePoints;
- use common\models\FlowWallet;
- use common\models\forms\DecPackageForm;
- use common\models\forms\ExcelOrderDecForm;
- use common\models\forms\ExcelOrderShopForm;
- use common\models\forms\ExcelOrderStandardForm;
- use common\models\forms\OrderDeleteForm;
- use common\models\forms\OrderForm;
- use common\models\forms\OrderPeriodAdjustForm;
- use common\models\forms\ShopGoodsForm;
- use common\models\forms\UploadForm;
- use common\models\Order;
- use common\models\OrderPeriodAdjust;
- use common\models\Period;
- use common\models\ShopGoods;
- use common\models\User;
- use common\models\UserInfo;
- use yii\web\UploadedFile;
- use yii\base\Exception;
- class ShopController extends BaseController {
- public $modelClass = DecOrder::class;
- public function behaviors() {
- $behaviors = parent::behaviors();
- //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
- return $behaviors;
- }
- /**
- * 商品列表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionIndex() {
- $filter = $this->filterCondition([
- 'TYPE'=> 'TYPE',
- 'GIFT_TYPE'=> 'GIFT_TYPE',
- 'STATUS'=> 'STATUS',
- 'GOODS_NAME'=> 'GOODS_NAME',
- 'GOODS_NO'=> 'GOODS_NO',
- 'SELL_TYPE'=> 'SELL_TYPE',
- 'SELL_PRICE'=> 'SELL_PRICE',
- 'PRICE_PV'=> 'PRICE_PV',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' ';
- $listObj = new GoodsList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 商品列表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionGoodsListExport()
- {
- $filter = $this->filterCondition([
- 'TYPE'=> 'TYPE',
- 'GIFT_TYPE'=> 'GIFT_TYPE',
- 'STATUS'=> 'STATUS',
- 'GOODS_NAME'=> 'GOODS_NAME',
- 'GOODS_NO'=> 'GOODS_NO',
- 'SELL_TYPE'=> 'SELL_TYPE',
- 'SELL_PRICE'=> 'SELL_PRICE',
- 'PRICE_PV'=> 'PRICE_PV',
- ]);
- $form = new ShopExportForm();
- $result = $form->run($filter, '商品列表');
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice('导出开始,请到文件管理-导出文件查看');
- }
- /**
- * 添加商品
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionGoodsAdd() {
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'add';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
- return static::notice('商品添加成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- return static::notice(['sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
- }
- /**
- * 编辑商品
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionGoodsEdit() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'edit';
- $formModel->id = $id;
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
- return static::notice('商品编辑成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
- }
- }
- $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
- $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
- $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
-
- return static::notice(['goodsInfo'=>$data,'sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
- }
- /**
- * 上传图片
- * @return mixed
- * @throws \yii\base\Exception
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionUpload(){
- if(\Yii::$app->request->isPost){
- $formModel = new UploadForm();
- $formModel->scenario = 'goodsImg';
- $formModel->file = UploadedFile::getInstanceByName('file');
- $formModel->token = \Yii::$app->request->request('uploadToken');
- if($formModel->file && $uploader = $formModel->upload()){
- return static::notice($uploader->URL);
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } else {
- $token = Cache::setUploadToken();
- return static::notice($token);
- }
- }
- /**
- * 商品上下架
- * @return mixed
- * @throws Exception
- */
- public function actionGoodsStatus() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new ShopGoodsForm();
- $formModel->scenario = 'changeStatus';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
- // foreach ($result['logs'] as $k => $value) {
- // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
- // }
- return static::notice('状态设置成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 删除商品
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionGoodsDelete(){
- $result = static::delete(ShopGoods::class);
- return $result;
- }
- /**
- * 套餐列表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionPackage() {
- $filter = $this->filterCondition([
- 'LEVEL_NAME'=> 'DP.LEVEL_ID',
- 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
- 'AMOUNT'=> 'DP.AMOUNT',
- 'PV'=> 'DP.PV',
- 'STATUS'=> 'DP.STATUS',
- 'STORE_NUMS'=>'DP.STORE_NUMS',
- 'STATUS_DATE'=>'DP.STATUS_DATE',
- 'PACKAGE_DATE'=>'DP.PACKAGE_DATE',
- 'PACKAGE_STATUS_DATE'=>'DP.PACKAGE_STATUS_DATE'
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND DP.IS_DEL=0';
- $listObj = new PackageList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 添加报单套餐
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionPackageAdd() {
- if (\Yii::$app->request->isPost) {
- return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
- // Log::adminHandle('添加报单套餐', 1);
- });
- }
- return static::notice('非发请求', 405);
- }
- /**
- * 报单套餐获取
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionPackageGet() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
- // Log::adminHandle('编辑报单套餐', 1);
- });
- }
- $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
- return static::notice(['id' => $package['ID'], 'packageName' => $package['PACKAGE_NAME'],'packageNo' => $package['PACKAGE_NO'], 'amount' => $package['AMOUNT'], 'amountPv' => $package['PV'], 'levelId' => $package['LEVEL_ID'], 'packageContent' => $package['PACKAGE_CONTENT'],'storenums' => $package['STORE_NUMS'],'statusdate'=>$package['STATUS_DATE'],'packagedate'=>$package['PACKAGE_DATE'],'packagestatusdate'=>$package['PACKAGE_STATUS_DATE'],'sort'=>$package['SORT']]);
- }
- /**
- * 套餐上下架
- * @return mixed
- * @throws Exception
- */
- public function actionPackageStatus() {
- $id = \Yii::$app->request->get('id');
- if (\Yii::$app->request->isPost) {
- $formModel = new DecPackageForm();
- $formModel->scenario = 'changeStatus';
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
- return static::notice('状态设置成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 删除套餐
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionPackageDelete(){
- $result = static::delete(DeclarationPackage::class);
- return $result;
- }
- /**
- * 报单表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionDecOrderList() {
- $filter = $this->filterCondition([
- 'DEC_SN'=> 'DO.DEC_SN',
- 'ORDER_SN'=> 'DO.ORDER_SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'TO_USER_NAME'=> 'TU.USER_NAME',
- 'REAL_NAME'=> 'TU.REAL_NAME',
- 'ID_CARD'=> 'TU.ID_CARD',
- 'MOBILE'=> 'TU.MOBILE',
- 'DEC_LV_NAME' => 'TU.DEC_LV',
- 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
- 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
- 'DEC_PV'=> 'DO.DEC_PV',
- 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
- 'REC_USER_NAME'=> 'RU.USER_NAME',
- 'CREATED_AT'=> 'DO.CREATED_AT',
- 'UPDATED_AT'=> 'DO.UPDATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND DO.IS_DEL=0';
- $listObj = new DecOrderList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 报单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionDecOrderListExport()
- {
- $filter = $this->filterCondition([
- 'DEC_SN'=> 'DO.DEC_SN',
- 'ORDER_SN'=> 'DO.ORDER_SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'TO_USER_NAME'=> 'TU.USER_NAME',
- 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
- 'DEC_PV'=> 'DO.DEC_PV',
- 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
- 'CREATED_AT'=> 'DO.CREATED_AT',
- 'UPDATED_AT'=> 'DO.UPDATED_AT',
- ]);
- $filter['condition'] .= ' AND DO.IS_DEL=0';
- $form = new ShopExportForm();
- $result = $form->run($filter, '报单列表');
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice('导出开始,请到文件管理-导出文件查看');
- }
- /**
- * 订单表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'PAY_TYPE'=> 'O.PAY_TYPE',
- ]);
- // $condition = ' 1=1 ' . $filter['condition'];
- // $params = $filter['params'];
- // $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- // 删除订单
- public function actionDeleteOrder() {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderDeleteForm();
- if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
- return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- }
- }
- /**
- * 订单表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderListExport()
- {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'MOBILE'=> 'O.MOBILE',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- 'PAY_TYPE'=> 'O.PAY_TYPE',
- ]);
- // $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
- $filter['condition'] .= ' AND O.IS_DELETE=0';
- $form = new ShopExportForm();
- $result = $form->run($filter, '订单列表');
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice('导出开始,请到文件管理-导出文件查看');
- }
- /**
- * 外部商城订单列表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderShopList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderShopList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 外部商城报单列表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderDecList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderDecList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 分页导入excel文件到待导入数据的表中
- * @return mixed
- */
- public function actionImportOrderShopToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $orderType = \Yii::$app->request->post('orderType');
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- $excelOrderShop = new ExcelOrderShopForm();
- $excelOrderShop->checkStatus($orderDay,$orderType);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
- } catch (\Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('发生错误:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 导入完成标记
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionImportOrderShop() {
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $orderType = \Yii::$app->request->post('orderType');
- $excelOrderShop = new ExcelOrderShopForm();
- $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('状态更新错误', 400);
- }
- }
- /**
- * 报单订单——分页导入excel文件到待导入数据的表中
- * @return mixed
- */
- public function actionImportOrderDecToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- $excelOrderShop = new ExcelOrderDecForm();
- $excelOrderShop->checkStatus($orderDay);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
- } catch (\Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('发生错误:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 报单订单导入完成标记
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionImportOrderDec() {
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderDay = \Yii::$app->request->post('orderDay');
- $excelOrderShop = new ExcelOrderDecForm();
- $finishStatus = $excelOrderShop->finished($orderDay);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('状态更新错误', 400);
- }
- }
- /**
- * 见习达标订单列表
- * @return mixed
- * @throws Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderStandardList() {
- $filter = $this->filterCondition([
- 'SN'=> 'O.SN',
- 'USER_NAME'=> 'U.USER_NAME',
- 'PERIOD_NUM'=> 'O.PERIOD_NUM',
- 'CREATED_AT'=> 'O.CREATED_AT',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $condition .= ' AND O.IS_DELETE=0';
- $listObj = new OrderStandardList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 分页导入excel文件到待导入数据的表中
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionImportOrderStandardToExcelTable()
- {
- // 先上传到服务器文件
- if (\Yii::$app->request->isPost) {
- $excelImportId = \Yii::$app->request->post('excelImportId');
- $rowCount = \Yii::$app->request->post('rowCount');
- //$periodNum = \Yii::$app->request->post('periodNum');
- $orderMonth = \Yii::$app->request->post('orderMonth');
- // $orderType = \Yii::$app->request->post('orderType');
- $orderType = 'cash';
- $startRow = \Yii::$app->request->post('startRow');
- $limit = \Yii::$app->request->post('limit', 1000);
- $errorMsg = '';
- try {
- if( $startRow == 1 ) {
- //清空已经导入的表数据
- $excelOrderStandard = new ExcelOrderStandardForm();
- $excelOrderStandard->checkStatus($orderMonth);
- }
- $excel = new \common\helpers\Excel();
- $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
- } catch (Exception $e) {
- $result = false;
- $errorMsg = $e->getMessage();
- }
- // 还有数据
- if ($result === 1) {
- return static::notice(['finish' => false]);
- } elseif ($result === 0) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('发生错误:' . $errorMsg, 400);
- }
- }
- }
- /**
- * 达标订单导入完成标记
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionImportOrderStandard() {
- $orderMonth = \Yii::$app->request->post('orderMonth');
- $excelOrderStandard = new ExcelOrderStandardForm();
- $finishStatus = $excelOrderStandard->finished($orderMonth);
- if ($finishStatus) {
- return static::notice(['finish' => true]);
- } else {
- return static::notice('状态更新错误', 400);
- }
- }
- /**
- * 管理员发货
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionOrderDelivery() {
- if(\Yii::$app->request->isPost) {
- return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
- }
- return static::notice('非法请求', 400);
- }
- /*
- * 剩余BV页
- *
- */
- public function actionRemainPv()
- {
- $filter = $this->filterCondition([
- 'USER_NAME' => 'U.USER_NAME',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $listObj = new RemainPvList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /*
- * 剩余BV流水
- *
- */
- public function actionFlowRemainPv()
- {
- $filter = $this->filterCondition([
- 'USER_NAME' => 'U.USER_NAME',
- ]);
- $condition = $filter['condition'];
- $params = $filter['params'];
- $listObj = new FlowRemainPvList();
- $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
- return static::notice($data);
- }
- /**
- * 订单详情
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionOrderDetail()
- {
- $orderSn = \Yii::$app->request->get('orderSn');
- $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
- if (!$order) {
- return static::notice('订单不存在', 400);
- }
- $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? '首单' : '复消';
- // 如果当前订单所在期数已挂网,则不可调整
- $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
- if (!$period) {
- return static::notice('期数无效', 400);
- }
- if ($period['IS_SENT'] > 0) {
- return static::notice('订单已挂网', 400);
- }
- // 根据订单期数查询可调整期数
- $availablePeriod = [];
- if ($order['PERIOD_NUM']) {
- $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
- foreach ($availablePeriod as $k => $item) {
- $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
- }
- }
- return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
- }
- /**
- * 期数检查
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionPeriodInspect()
- {
- $modernPeriod = \Yii::$app->request->get('modernPeriod');
- $period = Period::getInfoByPeriodNum($modernPeriod);
- if (!$period) {
- return static::notice('期数不存在', 400);
- }
- if ($period['IS_SENT'] > 0) {
- return static::notice('调整后的期数已未挂网', 400);
- }
- }
- /**
- * 调整订单期数
- * @return mixed
- * @throws Exception
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionOrderPeriodAdjust()
- {
- if (\Yii::$app->request->isPost) {
- $formModel = new OrderPeriodAdjustForm();
- $formModel->scenario = 'orderPeriodAdjust';
- if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
- return static::notice('成功');
- } else {
- return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
- }
- } else {
- $filter = $this->filterCondition([
- 'ORDER_SN' => 'P.ORDER_SN',
- 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
- 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
- 'CREATED_AT'=> 'P.CREATED_AT',
- ]);
- $listObj = new OrderPeriodAdjustList();
- $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
- return static::notice($data);
- }
- }
- public function actionOrderPeriodAdjustBatch()
- {
- if (\Yii::$app->request->isPost) {
- $db = \Yii::$app->db;
- $transaction = $db->beginTransaction();
- $orderList = ['OS202407155451100565', 'OS202407155497101991', 'OS202407155010197515', 'OS202407151001025110', 'OS202407155154555055', 'OS202407155350101971', 'OS202407151021015253', 'OS202407155453484910', 'OS202407155257971029', 'OS202407151015550579', 'OS202407151029810049', 'OS202407151015353100', 'OS202407151029710056', 'OS202407155648984997', 'OS202407159797505549', 'OS202407159950575510', 'OS202407151025157579', 'OS202407156368616462', 'OS202407153686680808', 'OS202407151866633642', 'OS202407159888884819', 'OS202407155145211080', 'OS202407156292514222', 'OS202407157498678208', 'OS202407154268431512', 'OS202407154454882264', 'OS202407158328464944', 'OS202407156269518671', 'OS202407152225442447', 'OS202407153626932624', 'OS202407152902269288', 'OS202407154599064628', 'OS202407156332118889', 'OS202407156278821714', 'OS202407156422844890', 'OS202407152820665483', 'OS202407156222856308', 'OS202407158940058473', 'OS202407152968228826', 'OS202407152124321121', 'OS202407153942346423', 'OS202407159636738258', 'OS202407154054291226', 'OS202407158419860442', 'OS202407152378625242', 'OS202407157406402262', 'OS202407150842868398', 'OS202407158762770086', 'OS202407156692230520', 'OS202407151282644686', 'OS202407152876612297', 'OS202407155492488603', 'OS202407154643842116', 'OS202407150848634326', 'OS202407155254481015', 'OS202407151015710299', 'OS202407154850579757', 'OS202407151009849575', 'OS202407154850505457', 'OS202407155256989857', 'OS202407151019756101', 'OS202407155798102995', 'OS202407151005498975', 'OS202407159754481029', 'OS202407159953994855', 'OS202407159897974950', 'OS202407151005197995', 'OS202407155152554855', 'OS202407151014810154', 'OS202407154857515052', 'OS202407159850515497', 'OS202407154848511015', 'OS202407151015150495', 'OS202407155654514950', 'OS202407159850494897', 'OS202407159957549955', 'OS202407155652565699', 'OS202407155348519750', 'OS202407155252515757', 'OS202407155149555254', 'OS202407155256971025', 'OS202407155055554955', 'OS202407155797534856', 'OS202407155597499997', 'OS202407151015053971', 'OS202407155149501029', 'OS202407159852541009', 'OS202407159954559951', 'OS202407155256991004', 'OS202407151025054484', 'OS202407155557101525', 'OS202407159849519854', 'OS202407155656102481', 'OS202407155010150541', 'OS202407155699989857', 'OS202407154948535210', 'OS202407155656535199', 'OS202407154899535310', 'OS202407154999501011', 'OS202407157127728482', 'OS202407150405654400', 'OS202407154287490762', 'OS202407155118248508', 'OS202407156504641725', 'OS202407153234072342', 'OS202407158426637622', 'OS202407152820068282', 'OS202407150029460590', 'Os202407150148542116', 'OS202407151240874672', 'OS202407154730144249', 'OS202407158844241634', 'OS202407158863686822', 'OS202407155040222463', 'OS202407153089830028', 'OS202407158408599616', 'OS202407155153525351', 'OS202407154852575149', 'OS202407156437484223', 'OS202407155210010156', 'OS202407151005753511', 'OS202407154954102575', 'OS202407155197491009', 'OS202407155297554852', 'OS202407154910198102', 'OS202407155250102481', 'OS202407155398539849', 'OS202407155355102481', 'OS202407159749535352', 'OS202407151019998514', 'OS202407151001005097', 'OS202407151015750495', 'OS202407151001009799', 'OS202407159757981001', 'OS202407155251534853', 'OS202407159854515554', 'OS202407159950524910', 'OS202407155653102511', 'OS202407155657529850', 'OS202407151009748555', 'OS202407155052100515', 'OS202407159752534850', 'OS202407154853495457', 'OS202407159756535550', 'OS202407151005756575', 'OS202407155348544999', 'OS202407155652525398', 'OS202407155151485151', 'OS202407155750559756', 'OS202407155151565453', 'OS202407151015149519', 'OS202407155710110110', 'OS202407159997989797', 'OS202407152646361222', 'OS202407151364466942', 'OS202407154460456414', 'OS202407159063081989', 'OS202407153679443648', 'OS202407150494868576', 'OS202407157008828988', 'OS202407154428221117', 'OS202407156202440942', 'OS202407158544552420', 'OS202407154868229881', 'OS202407152163616464', 'OS202407152282282440', 'OS202407158848486304', 'OS202407151938188260', 'OS202407155254696340', 'OS202407159147586849', 'OS202407158549360845', 'OS202407156447048982', 'OS202407150887831643', 'OS202407159729782028', 'OS202407150881941246', 'OS202407159997519954', 'OS202407155050485248', 'OS202407155656505555', 'OS202407154951995010', 'OS202407155410151555', 'OS202407155198511015', 'OS202407155349549797', 'OS202407151024957102', 'OS202407155453102575', 'OS202407155148549848', 'OS202407159855565652', 'OS202407154997995051', 'OS202407154897102981', 'OS202407155751519897', 'OS202407155252495756', 'OS202407155597555252', 'OS202407155497565549', 'OS202407155697991005', 'OS202407151015154501', 'OS202407155654975754', 'OS202407154810151100', 'OS202407159957102975', 'OS202407159951495348', 'OS202407155610248555', 'OS202407154849102569', 'OS202407154810051995', 'OS202407155451101985', 'OS202407155599101555', 'OS202407151009898539', 'OS202407159753579854', 'OS202407155254555148', 'OS202407155257491005', 'OS202407155598539955', 'OS202407151009855515', 'OS202407155253535157', 'OS202407159755495110', 'OS202407151015451102', 'OS202407151005251555', 'OS202407151025451985', 'OS202407154910050485', 'OS202407154854515198', 'OS202407159756575352', 'OS202407151025757565', 'OS202407155351975254', 'OS202407151024852995', 'OS202407154854525354', 'OS202407155357999753', 'OS202407159798101559', 'OS202407151015556515', 'OS202407155510010199', 'OS202407155799999954', 'OS202407159854102974', 'OS202407151015155102', 'OS202407151001005210', 'OS202407151005399554', 'OS202407159757545453', 'OS202407155510157101', 'OS202407155597991005', 'OS202407159750984898', 'OS202407155357565656', 'OS202407155654555354', 'OS202407159851981029', 'OS202407155455100535', 'OS202407159799505653', 'OS202407159752975548', 'OS202407155210010049', 'OS202407155250975197', 'OS202407155152554999', 'OS202407155449545255', 'OS202407159748555798', 'OS202407155650524956', 'OS202407155656545448', 'OS202407159855485797', 'OS202407159948974956', 'OS202407155653995651', 'OS202407159998985554', 'OS202407155048975256', 'OS202407155097565255', 'OS202407155610099505', 'OS202407159898985155', 'OS202407159910199515', 'OS202407155399481014', 'OS202407159810098535', 'OS202407151019851995', 'OS202407155652100101', 'OS202407151019997541', 'OS202407155053511015', 'OS202407155453555510', 'OS202407155357505198', 'OS202407151025750975', 'OS202407151005757495', 'OS202407155056505210', 'OS202407155553571005', 'OS202407155748579854', 'OS202407155698971005', 'OS202407151025648100', 'OS202407155310199102', 'OS202407154953489953', 'OS202407154948555457', 'OS202407151009956101', 'OS202407151001011011', 'OS202407154955514950', 'OS202407155299985252', 'OS202407159749995653', 'OS202407155598100975', 'OS202407151005697565', 'OS202407159752495297', 'OS202407155655995055', 'OS202407159849995699', 'OS202407155649515450', 'OS202407155455101515', 'OS202407155410110155', 'OS202407155410150101', 'OS202407155549515656', 'OS202407155697565110', 'OS202407154952545699', 'OS202407155554481029', 'OS202407155053481021', 'OS202407155110098559', 'OS202407154950101549', 'OS202407155699101100', 'OS202407154850505710', 'OS202407159853101571', 'OS202407155655555510', 'OS202407151019810156', 'OS202407155248100541', 'OS202407154854102511', 'OS202407154956575010', 'OS202407151015010148', 'OS202407155654495152', 'OS202407155510098100', 'OS202407159757979855', 'OS202407159897505254', 'OS202407155710110154', 'OS202407159950100491', 'OS202407151024853534', 'OS202407155254565452', 'OS202407154851519853', 'OS202407155110199101', 'OS202407159899505055', 'OS202407151009948100', 'OS202407155054481021', 'OS202407154949525110', 'OS202407151015210110', 'OS202407154953495255', 'OS202407155010053569', 'OS202407155699481004', 'OS202407155350102519', 'OS202407155110054505', 'OS202407159954569850', 'OS202407159897985753', 'OS202407155353515010', 'OS202407159754979810', 'OS202407155755515710', 'OS202407155148555610', 'OS202407155451489710', 'OS202407155698515697', 'OS202407155552975553', 'OS202407155555100535', 'OS202407159752539999', 'OS202407151025249549', 'OS202407151025499495', 'OS202407155150989798', 'OS202407155755985050', 'OS202407155252494998', 'OS202407154910010010', 'OS202407155697505656', 'OS202407151906641278', 'OS202407151040648048', 'OS202407158088895422', 'os202407154682364248', 'OS202407152894226818', 'OS202407158238546244', 'OS202407156524616028', 'OS202407156634522776', 'OS202407156184598609', 'OS202407158787863470', 'OS202407156501188958', 'OS202407156629952496', 'OS202407152724683349', 'OS202407157881845462', 'OS202407150428883432', 'OS202407158840286765', 'OS202407154166664061', 'OS202407155119771160', 'OS202407156930403340', 'OS202407156575948642', 'OS202407157872048740', 'OS202407154606142868', 'OS202407157222946892', 'OS202407154769803282', 'OS202407158466043400', 'OS202407150801122367', 'OS202407155006148567', 'OS202407156728224495', 'OS202407158912984426', 'OS202407150021662442', 'OS202407150399219823', 'OS202407151798648080', 'OS202407152960126545', 'OS202407156681246353', 'OS202407154439292289', 'OS202407154643241834', 'OS202407159490669156', 'OS202407156345315802', 'OS202407152256076428', 'OS202407155150504948', 'OS202407154852975552', 'OS202407159954544851', 'OS202407151025010157', 'OS202407155652101555', 'OS202407159710154525', 'OS202407159749985452', 'OS202407151015348531', 'OS202407155050102995', 'OS202407154955525148', 'OS202407159755535510', 'OS202407155154539851', 'OS202407155050525156', 'OS202407151005454579', 'OS202407155250544954', 'OS202407159856999898', 'OS202407159848535097', 'OS202407159710051101', 'OS202407154999561005', 'OS202407155799541004', 'OS202407151025498551', 'OS202407159852515157', 'OS202407155357575548', 'OS202407151025610098', 'OS202407159856549753', 'OS202407155497101535', 'OS202407155510097515', 'OS202407154910157515', 'OS202407151005197101', 'OS202407159955574850', 'OS202407156482426702', 'OS202407155444646224', 'OS202407150226599448', 'OS202407156122578684', 'OS202407156448624252', 'OS202407158848662460'];
- $orderErr = [];
- try {
- $modernPeriod = 223;
- foreach ($orderList as $orderSn) {
- $orderObj = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
- if (!$orderObj) {
- $orderErr[] = $orderSn;
- continue;
- }
- // 调整订单期数
- Order::updateAll(['PERIOD_NUM' => $modernPeriod], 'SN = :SN', [':SN' => $orderSn]);
- if ($orderObj['ORDER_TYPE'] === 'ZC') {
- // 调整报单期数
- DecOrder::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- // 调整会员的期数
- User::updateAll(['PERIOD_AT' => $modernPeriod], 'ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
- UserInfo::updateAll(['HIGHEST_EMP_LV_PERIOD' => $modernPeriod], 'USER_ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
- }
- // 调整流水的期数
- switch ($orderObj['PAY_TYPE']){
- case 'cash':
- FlowWallet::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- break;
- case 'point':
- FlowReconsumePoints::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- break;
- case 'exchange':
- FlowExchangePoints::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
- break;
- default:
- break;
- }
- // 写入调整记录
- $orderModel = new OrderPeriodAdjust();
- $orderModel->ORDER_SN = $orderSn;
- $orderModel->ORIGIN_PERIOD = 224;
- $orderModel->MODERN_PERIOD = $modernPeriod;
- $orderModel->ADMIN_ID = '3rwvmynvct';
- $orderModel->CREATED_AT = Date::nowTime();
- if (!$orderModel->save()) {
- return static::notice($orderModel->getErrors(), 400);
- }
- }
- $transaction->commit();
- } catch(\Exception $e) {
- $transaction->rollBack();
- return static::notice($e->getMessage(), 400);
- }
- return static::notice('成功. ' . json_encode($orderErr));
- }
- }
- }
|