ApplyController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace addons\Alitopay\backend\controllers;
  3. use addons\Alitopay\backend\controllers\BaseController;
  4. use addons\Alitopay\common\models\Apply;
  5. use addons\Alitopay\common\services\ApplyService;
  6. use app\models\MallSetting;
  7. use app\plugins\ali_to_pay\forms\mall\AlitopayForm;
  8. use app\plugins\ali_to_pay\models\AliTopay;
  9. use app\plugins\Controller;
  10. use app\services\ReturnData;
  11. use http\Url;
  12. use Yii;
  13. class ApplyController extends BaseController
  14. {
  15. public $enableCsrfValidation = false;
  16. public $service;
  17. public function __construct ($id, $module, $config = [])
  18. {
  19. parent::__construct($id, $module, $config);
  20. $this->service = new ApplyService();
  21. }
  22. public function actionIndex(){
  23. if(!Yii::$app->request->isAjax){
  24. return $this->render('index');
  25. }
  26. $data = $this->service->getApply($this->mall_id);
  27. return $this->success('ok',$data);
  28. }
  29. /**
  30. * 编辑审核
  31. * @desc
  32. * @return mixed|void
  33. * @throws \yii\db\Exception
  34. */
  35. public function actionEdit(){
  36. $post = Yii::$app->request->post();
  37. $id = $post['id'] ?? 0;
  38. if($id > 0){
  39. $post['status'] = 1;
  40. $post['reason'] = '';
  41. $model = Apply::findOne($id);
  42. }else{
  43. $model = new Apply();
  44. }
  45. if($model->isNewRecord){
  46. $post['deal_sn'] = date('YmdHis').rand(1000,9999);
  47. }
  48. $post['mall_id'] = $this->mall_id;
  49. $db = Yii::$app->db->beginTransaction();
  50. if( !($model->load($post,'') && $model->validate() && $model->save()) ){
  51. return $this->error($model->getFirstErrors());
  52. }
  53. $service = new ApplyService();
  54. $result = $service->apply($this->mall_id,$model);
  55. if($result){
  56. $db->commit();
  57. return $this->success('提交成功,请等待审核');
  58. }else{
  59. $db->rollBack();
  60. return $this->error($service->error);
  61. }
  62. }
  63. }