예제 #1
0
 public function actionPass($id)
 {
     $model = Apply::findOne(['id' => $id, 'status' => Apply::STATUS_PENDING]);
     if (!$model) {
         throw new BadRequestHttpException('参数错误!');
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $model->status = Apply::STATUS_PASSED;
         if (!$model->save(false)) {
             throw new \Exception('操作失败!');
         }
         $modelApplyLog = new ApplyLog();
         $modelApplyLog->apply_id = $id;
         $modelApplyLog->remark = '申请通过。';
         if (!$modelApplyLog->save(false)) {
             throw new \Exception('申请日志记录失败!');
         }
         $transaction->commit();
         if (!empty($model->store->cellphone)) {
             Yii::$app->smser->send($model->store->cellphone, "亲爱的店长,恭喜您的采购订单{$model->apply_sn}申请成功,我们的工作人员很快会与您取得联系。");
         }
         Yii::$app->session->setFlash('success', '操作成功!');
     } catch (\Exception $e) {
         $transaction->rollBack();
         Yii::$app->session->setFlash('danger', $e->getMessage());
     }
     return $this->redirect(['view', 'id' => $id]);
 }
예제 #2
0
 /**
  * Creates a form model given an apply id.
  *
  * @param  string                          $id
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if waybill sn is empty or not valid
  */
 public function __construct($id, $config = [])
 {
     if (empty($id) || !is_numeric($id)) {
         throw new InvalidParamException('参数错误!');
     }
     $this->_apply = Apply::findOne($id);
     if (!$this->_apply) {
         throw new InvalidParamException('未找到该申请!');
     }
     if ($this->_apply->status !== Apply::STATUS_PENDING) {
         throw new InvalidParamException('请求错误!');
     }
     parent::__construct($config);
 }
예제 #3
0
 public function actionCancel($id)
 {
     $model = Apply::findOne(['id' => $id, 'status' => Apply::STATUS_REJECTED, 'store_id' => Yii::$app->user->identity->store_id]);
     if (!$model) {
         throw new BadRequestHttpException('参数错误!');
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $model->status = Apply::STATUS_CANCELLED;
         if (!$model->save(false)) {
             throw new \Exception('操作失败!');
         }
         $modelApplyLog = new ApplyLog();
         $modelApplyLog->apply_id = $id;
         $modelApplyLog->remark = '取消申请。';
         if (!$modelApplyLog->save(false)) {
             throw new \Exception('申请日志记录失败!');
         }
         $transaction->commit();
         Yii::$app->session->setFlash('success', '操作成功!');
     } catch (\Exception $e) {
         $transaction->rollBack();
         Yii::$app->session->setFlash('danger', $e->getMessage());
     }
     return $this->redirect(['view', 'id' => $id]);
 }