DefaultController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace addons\CardSecret\api\modules\v1\controllers;
  3. use addons\CardSecret\common\models\CardSecret;
  4. use addons\CardSecret\common\models\CardSecretGoods;
  5. use addons\CardSecret\common\models\CardSecretUse;
  6. use addons\CardSecret\common\models\Cate;
  7. use common\enums\OrderStatusEnum;
  8. use common\enums\StatusEnum;
  9. use common\models\order\Order;
  10. use common\models\order\OrderDetail;
  11. use Yii;
  12. use api\controllers\OnAuthController;
  13. /**
  14. * 默认控制器
  15. *
  16. * Class DefaultController
  17. * @package addons\CardSecret\api\modules\v1\controllers
  18. */
  19. class DefaultController extends OnAuthController
  20. {
  21. public $modelClass = '';
  22. /**
  23. * 不用进行登录验证的方法
  24. *
  25. * 例如: ['index', 'update', 'create', 'view', 'delete']
  26. * 默认全部需要验证
  27. *
  28. * @var array
  29. */
  30. protected $authOptional = ['goods'];
  31. /**
  32. * 首页
  33. *
  34. * @return string
  35. */
  36. public function actionGoods()
  37. {
  38. $retuest = Yii::$app->request;
  39. if ($retuest->isGet) {
  40. $params = Yii::$app->request->get();
  41. // 检查提交的参数
  42. $res = Yii::$app->services->validate->validate($params, [
  43. [['order_id'], 'safe']
  44. ]);
  45. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  46. // 查询订单
  47. $order = Order::findOne(['id' => $params['order_id']])->toArray();
  48. if ($order) {
  49. $goods_data = [];
  50. $with = ['cardSecret','goods'];
  51. $where = [];
  52. $where[] = ['=','order_id',$order['id']];
  53. $where[] = ['=','mall_id',$order['mall_id']];
  54. $where[] = ['=','status', StatusEnum::ENABLED];
  55. $params = array('where' => $where,'with' => $with, 'order'=>'id desc');
  56. $list['list'] = CardSecretUse::lists($params,true);
  57. if ($list && $order['order_status'] < OrderStatusEnum::SING){
  58. $list['status'] = 2; //提示收货成功后展示
  59. }else if(!$list){
  60. $list['status'] = 3;//卡密已经赠送完了
  61. }else{
  62. $list['status'] = 1;//正常显示
  63. }
  64. }
  65. return $this->successStr('操作成功', $list);
  66. }
  67. }
  68. }