| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace addons\Mch\console\controllers;
- use addons\Mch\common\enums\MchEnum;
- use addons\Mch\common\models\Mch;
- use common\enums\AddonsEnum;
- use common\models\goods\Goods;
- use common\models\mall\MallAddons;
- use yii\console\Controller;
- use common\models\mall\Mall;
- use common\enums\StatusEnum;
- use yii\console\ExitCode;
- use addons\Mch\common\models\SettlementLog;
- class IndexController extends Controller
- {
- public function actionIndex()
- {
- try {
- $mall_list = Mall::getEnableMallList(true);
- $mall_ids = array_column($mall_list, 'id');
- if (empty($mall_ids)) {
- echo '没有可用商城,不做处理 ... ' . PHP_EOL;
- return ExitCode::UNSPECIFIED_ERROR;
- }
- foreach ($mall_ids as $mall_id) {
- $is_install = MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_STORE);
- if(empty($is_install)) continue;
- $mch_list = Mch::find()
- ->select('id,store_name,logo_img,praise')
- ->where( ['mall_id' => $mall_id,'status' => StatusEnum::ENABLED, 'check_status' => MchEnum::CHECK_ADOPT])
- ->andWhere(['<', 'expire_time', time()])
- ->andWhere(['>', 'expire_time', 0])
- ->all();
- $mch_ids = array_column($mch_list,'id');
- Mch::updateAll(['status'=>StatusEnum::DISABLED],['id'=>$mch_ids]);
- Goods::updateAll(['is_on_sale'=>0],['mch_id'=>$mch_ids]);
- }
- return ExitCode::OK;
- } catch (\Exception $e) {
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- public function actionSettlementLog()
- {
- try {
- $logs = SettlementLog::find()
- ->where(['is_settlement'=>0])
- ->andWhere(['<','settlement_at',time()])
- ->all();
- if(!empty($logs)){
- foreach($logs as $log){
- $trans = \Yii::$app->db->beginTransaction();
- try{
- $log->is_settlement = 1;
- if(!$log->save()){
- throw new \Exception('门店订单结算异常,id:'.$log->id);
- }
- //结算货款
- Mch::settlementStoreCommission($log['order_id'], $log['store_id'], $log['order_no']);
- $trans->commit();
- }catch(\Exception $e){
- $trans->rollBack();
- throw new \Exception($e->getMessage());
- }
- }
- }
- return ExitCode::OK;
- } catch (\Exception $e) {
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- }
|