| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace addons\Purchase\backend\controllers;
- use Yii;
- use common\controllers\AddonsController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Purchase\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index',[
- ]);
- }
- public function actionGoods()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $get = Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['<>','status',StatusEnum::DELETE];
- if (isset($get['goods_name']) && !empty($get['goods_name'])) {
- $goodsLists = Goods::goodsSearchFromAddons('goods_name', $get['goods_name'], $this->mall_id);
- if (empty($goodsLists)) {
- return $this->success('操作成功', ['list' => []]);
- } else {
- $goodsIds = array_column($goodsLists, 'id');
- $where[] = ['goods_id' => $goodsIds];
- }
- }
- $params = [
- 'where' => $where,
- 'limit' => 10,
- 'select' => ['goods_id', 'num', 'created_at', 'money', 'type', 'price', 'score'],
- 'order' => 'created_at desc'
- ];
- $list = ScoreMallGoods::listPage($params);
- if ($list['list']) {
- $url = Yii::$app->services->setting->mall->get($this->mall_id, 'basic.web_url');
- $url = $url ?? '';
- $list['domain'] = $url;
- if (!isset($goodsLists)) {
- $goodsLists = Goods::find()
- ->select(['id', 'goods_name', 'cover_pic', 'price'])
- ->where(['in', 'id', array_column($list['list'], 'goods_id')])
- ->asArray()->indexBy('id')->all();
- }
- $goodsLists = array_column($goodsLists, null, 'id');
- foreach ($list['list'] as &$val) {
- $val['money'] = $val['money'] ?? '0.00';
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- $val['type_info'] = ScoreMallEnum::getTypeMap($val['type']);
- $val['goods_name'] = isset($goodsLists[$val['goods_id']]) ? $goodsLists[$val['goods_id']]['goods_name'] : '';
- $val['cover_pic'] = isset($goodsLists[$val['goods_id']]) ? $goodsLists[$val['goods_id']]['cover_pic'] : '';
- $val['price'] = isset($goodsLists[$val['goods_id']]) ? $goodsLists[$val['goods_id']]['price'] : '';
- }
- }
- return $this->success('操作成功', $list);
- }
- }
- return $this->render('index');
- }
- }
|