IndexController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace addons\Store\console\controllers;
  3. use addons\Store\common\listeners\order\OrderPaidListener;
  4. use addons\Store\common\models\SettlementLog;
  5. use addons\Store\common\models\Store;
  6. use yii\console\ExitCode;
  7. use yii\console\Controller;
  8. class IndexController extends Controller
  9. {
  10. public function actionSettlementLog()
  11. {
  12. try {
  13. $logs = SettlementLog::find()
  14. ->where(['is_settlement'=>0])
  15. ->andWhere(['<','settlement_at',time()])
  16. ->all();
  17. if(!empty($logs)){
  18. foreach($logs as $log){
  19. $trans = \Yii::$app->db->beginTransaction();
  20. try{
  21. $log->is_settlement = 1;
  22. if(!$log->save()){
  23. throw new \Exception('门店订单结算异常,id:'.$log->id);
  24. }
  25. //结算货款
  26. Store::settlementStoreCommission($log['order_id'], $log['store_id'], $log['order_no']);
  27. $trans->commit();
  28. }catch(\Exception $e){
  29. $trans->rollBack();
  30. throw new \Exception($e->getMessage());
  31. }
  32. }
  33. }
  34. return ExitCode::OK;
  35. } catch (\Exception $e) {
  36. return ExitCode::UNSPECIFIED_ERROR;
  37. }
  38. }
  39. public function actionTest()
  40. {
  41. OrderPaidListener::async_handle(['id' => 1092]);
  42. }
  43. }