SignController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace addons\Community\api\modules\v1\controllers;
  3. use addons\Community\common\service\SignService;
  4. use api\controllers\OnAuthController;
  5. use Yii;
  6. class SignController extends OnAuthController
  7. {
  8. public $modelClass = '';
  9. /**
  10. * 不用进行登录验证的方法
  11. *
  12. * 例如: ['index', 'update', 'create', 'view', 'delete']
  13. * 默认全部需要验证
  14. *
  15. * @var array
  16. */
  17. protected $authOptional = [];
  18. /**
  19. * 自提核销
  20. * @return mixed|null
  21. */
  22. public function actionCreate()
  23. {
  24. $data = Yii::$app->request->post();
  25. $valid = Yii::$app->services->validate->validate($data, [
  26. [['order_no'], 'string'],
  27. [['order_no'], 'required']
  28. ]);
  29. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  30. $ret = (new SignService())->create($this->mall_id, $data['order_no'], $this->user_id);
  31. return is_string($ret) ? $this->error($ret) : $this->success('核销成功');
  32. }
  33. /**
  34. * 团长代替买家进行收货
  35. * @return mixed|null
  36. */
  37. public function actionReceive()
  38. {
  39. $data = Yii::$app->request->post();
  40. $valid = Yii::$app->services->validate->validate($data, [
  41. [['order_no'], 'string'],
  42. [['order_id'], 'integer'],
  43. // [['order_no'], 'required'], // 变成ID了 - 因为使用ID核销
  44. ]);
  45. if (empty($data['order_no']) && empty($data['order_id'])) {
  46. return $this->error("订单编号不能为空");
  47. }
  48. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  49. $ret = (new SignService())->create($this->mall_id,
  50. !empty($data['order_no']) ? $data['order_no'] : $data['order_id'], $this->user_id,
  51. !empty($data['order_no']) ? 'order_no' : 'id');
  52. return is_string($ret) ? $this->error($ret) : $this->success('收货成功');
  53. }
  54. }