| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models\pt;
- use app\constants\OptionSetting;
- use app\jobs\storeSync\DiyCommon;
- use app\models\AboutArticle;
- use app\models\ActivityCutPrice;
- use app\models\ActivityCutPriceGoods;
- use app\models\ActivityNewUser;
- use app\models\ActivityNewUserGoods;
- use app\models\Cat;
- use app\models\DeliveryRules;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\models\Option;
- use app\models\PtActivity;
- use app\models\PtActivityGoods;
- use app\models\PtActivityGoodsCat;
- use app\models\PtActivityOrder;
- use app\models\PtActivityOrderDetail;
- use app\models\SeckillActivity;
- use app\models\SeckillActivityGoods;
- use app\models\SeckillActivityOrderLog;
- use app\models\Store;
- use app\models\StoreSyncExtLog;
- use yii\base\Model;
- class PtActivityForm extends Model
- {
- public $id;
- public $ids;
- public $name;
- public $store_name;
- public $is_use_coupon;
- public $start_time;
- public $end_time;
- public $goods;
- public $status;
- public $party_size;
- public $party_winner_size;
- public $join_num;
- public $cat_id;
- public $split_time;
- public $desc;
- public $head_is_free;
- public $head_integral;
- public $party_type;
- public $party_goods_count;
- public $is_platform = 0;
- public $is_platform_audit = 0;
- public $order_goods_limit;
- public function rules()
- {
- return [
- [['status', 'is_use_coupon', 'id', 'goods_id', 'party_size', 'join_num', 'cat_id', 'split_time', 'party_winner_size', 'head_is_free', 'head_integral', 'is_platform', 'is_platform_audit', 'order_goods_limit'], 'integer'],
- [['start_time', 'end_time', 'ids', 'name', 'desc', 'store_name'], 'string'],
- [['goods', 'party_type', 'party_goods_count'], 'safe']
- ];
- }
- public function search ()
- {
- try {
- $query = PtActivity::find()->where(['is_delete' => 0, 'is_platform' => $this->is_platform, 'store_id' => get_store_id()]);
- if ((int)$this->status === 1) {//未开始
- $query->andWhere(['>' , 'start_time', time()]);
- }
- if ((int)$this->status === 2) {//进行中
- $query->andWhere(['AND', ['<' , 'start_time', time()], ['>' , 'end_time', time()]]);
- }
- if ((int)$this->status === 3) { //已结束
- $query->andWhere(['<' , 'end_time', time()]);
- }
- if (!empty($this->name)) { //名称
- $query->andWhere(['LIKE' , 'name', $this->name]);
- }
- if (!empty($this->start_time) && !empty($this->end_time)) { //时间筛选
- $query->andWhere(['OR',
- ['AND',
- ['<=' , 'start_time', strtotime($this->start_time)],
- ['>=' , 'end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['<=' , 'start_time', strtotime($this->start_time)],
- ['<=' , 'end_time',strtotime($this->end_time)],
- ['>=' , 'end_time',strtotime($this->start_time)]
- ],
- ['AND',
- ['>=' , 'start_time', strtotime($this->start_time)],
- ['<=' , 'end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['>=' , 'start_time', strtotime($this->start_time)],
- ['>=' , 'end_time',strtotime($this->end_time)],
- ['<=' , 'start_time',strtotime($this->end_time)]
- ],
- ]);
- }
- $query->select('id, start_time, end_time, created_at, updated_at, name, party_type, party_goods_count, party_size pt_join_num, is_platform_audit')->orderBy('created_at desc');
- $pagination = pagination_make($query);
- foreach ($pagination['list'] as &$item) {
- //获取活动状态
- if ($item['start_time'] > time()) {
- $item['status'] = 1;
- }
- if ($item['start_time'] < time() && $item['end_time'] > time()) {
- $item['status'] = 2;
- }
- if ($item['end_time'] < time()) {
- $item['status'] = 3;
- }
- $item['is_platform_audit'] = (int)$item['is_platform_audit'];
- //格式化时间
- $item['start_time'] = date("Y-m-d H:i:s", $item['start_time']);
- $item['end_time'] = date("Y-m-d H:i:s", $item['end_time']);
- $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- $item['updated_at'] = $item['updated_at'] ? date("Y-m-d H:i:s", $item['updated_at']) : '';
- //计算订单数量 订单金额
- $pt_order = PtActivityOrderDetail::find()->alias('od')->where(['od.activity_id' => $item['id']])
- ->leftJoin(['o' => PtActivityOrder::tableName()], 'od.order_id = o.id')
- ->andWhere(['o.is_winner' => 1])->select('o.total_price')->column();
- $item['pt_order_count'] = count($pt_order); //成团订单数量
- $item['pt_total_price'] = array_sum($pt_order); //订单金额
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $pagination['list'],
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function getGoodsCat()
- {
- try {
- $goods_cat = PtActivityGoodsCat::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->
- select('id, name')->orderBy('created_at desc')->asArray()->all();
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => [
- 'data' => $goods_cat,
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function getInfo()
- {
- try {
- $activity = PtActivity::find()->where(['id' => $this->id, 'is_delete' => 0])->one();
- if ($activity) {
- $activity_goods = PtActivityGoods::find()->alias('pag')->leftJoin(['g' => Goods::tableName()], 'g.id = pag.goods_id')
- ->where(['pag.activity_id' => $activity->id, 'pag.is_delete' => 0, 'g.is_delete' => 0])
- ->select('g.id, g.name, g.cover_pic, pag.attr, g.use_attr, g.price, g.goods_num, pag.virtual_sales, pag.sale_num, pag.pt_price, pag.cat_id')
- ->asArray()->all();
- foreach ($activity_goods as &$activity_good) {
- $activity_good['attr'] = json_decode($activity_good['attr'], true);
- foreach ($activity_good['attr'] as &$attr) {
- if (!$attr['pic']) {
- $attr['pic'] = $activity_good['cover_pic'];
- }
- }
- }
- $activity['start_time'] = date("Y-m-d H:i:s", $activity['start_time']);
- $activity['end_time'] = date("Y-m-d H:i:s", $activity['end_time']);
- $activity['head_is_free'] = (int)$activity['head_is_free'];
- $activity['order_goods_limit'] = (int)$activity['order_goods_limit'];
- }
- return [
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'activity_goods' => $activity_goods ?? [],
- 'activity' => $activity ?: []
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage() . $e->getFile() . $e->getLine()
- ];
- }
- }
- public function save ()
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- if (!$this->name || !$this->start_time || !$this->end_time || !$this->goods) {
- throw new \Exception("请将参数填充完整");
- }
- if (intval($this->party_size) < intval($this->party_winner_size)) {
- throw new \Exception("拼团成功人数不能大于成团人数");
- }
- $activity = PtActivity::findOne(['id' => $this->id, 'is_delete' => 0, 'store_id' => get_store_id()]);
- if (empty($activity)) {
- $activity = new PtActivity();
- $activity->store_id = get_store_id();
- } else {
- $split_time = $activity->split_time * 3600;
- $split_time = time() - $split_time;
- //判断是否有拼团进行中的订单
- $ptActivityOrderDetail = PtActivityOrderDetail::find()->alias('od')
- ->leftJoin(['o' => PtActivityOrder::tableName()], 'o.id = od.order_id')
- ->where(['od.activity_id' => $this->id, 'o.is_pt_finish' => 0, 'o.is_pay' => 1])
- ->andWhere(['>=', 'o.pay_time', $split_time])
- ->asArray()->one();
- if ($ptActivityOrderDetail) {
- throw new \Exception("当前活动存在未完成的拼团订单,请等待拼团完成后再修改信息");
- }
- }
- // else {
- // SeckillActivityGoods::updateAll(['is_delete' => 1], ['activity_id' => $activity->id]);
- // }
- $head_is_free = (int)$this->head_is_free;
- if (!in_array($head_is_free, [0, 1])) {
- throw new \Exception("团长是否免单状态错误");
- }
- $activity->party_type = $this->party_type;
- $this->party_goods_count && $activity->party_goods_count = $this->party_goods_count;
- $activity->head_integral = $this->head_integral;
- $activity->head_is_free = $head_is_free;
- $activity->name = $this->name;
- $activity->start_time = strtotime($this->start_time);
- $activity->end_time = strtotime($this->end_time);
- $activity->party_size = (int)$this->party_size;
- $activity->party_winner_size = (int)$this->party_winner_size;
- $activity->join_num = (int)$this->join_num;
- $activity->split_time = (int)$this->split_time;
- $activity->is_platform = (int)$this->is_platform;
- $activity->order_goods_limit = (int)$this->order_goods_limit;
- if (!$activity->save()) {
- throw new \Exception(json_encode($activity->errors));
- }
- $goods = $this->goods;
- $open = false;
- foreach ($goods as $item) {
- $Goods = Goods::find()->where(['id' => $item['id'], 'store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->select('id, use_attr, name, attr, price')->one();
- if ($Goods) {
- $old_goods = PtActivityGoods::findOne(['activity_id' => $activity->id, 'is_delete' => 0, 'goods_id' => $item['id']]);
- $sale_num = 0;
- if ($old_goods) {
- $sale_num = $old_goods->sale_num;
- PtActivityGoods::updateAll(['is_delete' => 1], ['activity_id' => $activity->id, 'is_delete' => 0]);
- } else {
- $open = true;
- }
- //验证是否存在其他时间段(未开始 / 进行中)相同的活动产品
- $is_exist_goods = PtActivityGoods::find()->alias('pag')->where(['pag.goods_id' => $item['id'], 'pag.store_id' => get_store_id()])
- ->leftJoin(['pg' => PtActivity::tableName()], 'pag.activity_id = pg.id')
- ->andWhere(['<>', 'pg.id', $activity->id])
- ->andWhere(['OR',
- ['AND',
- ['<=' , 'pg.start_time', strtotime($this->start_time)],
- ['>=' , 'pg.end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['<=' , 'pg.start_time', strtotime($this->start_time)],
- ['<=' , 'pg.end_time',strtotime($this->end_time)],
- ['>=' , 'pg.end_time',strtotime($this->start_time)]
- ],
- ['AND',
- ['>=' , 'pg.start_time', strtotime($this->start_time)],
- ['<=' , 'pg.end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['>=' , 'pg.start_time', strtotime($this->start_time)],
- ['>=' , 'pg.end_time',strtotime($this->end_time)],
- ['<=' , 'pg.start_time',strtotime($this->end_time)]
- ],
- ])->andWhere(['pg.is_delete' => 0, 'pag.is_delete' => 0])->select('pag.id, pag.activity_id')->one();
- if ($is_exist_goods) {
- throw new \Exception("部分商品已经在其他未开始/进行中的活动中");
- }
- //验证相同时间段是否存在其他活动产品(新人专享)
- // $is_exist_goods = ActivityNewUserGoods::find()->alias('pag')->where(['pag.goods_id' => $item['id'], 'pag.store_id' => get_store_id()])
- // ->leftJoin(['pg' => ActivityNewUser::tableName()], 'pag.activity_id = pg.id')
- // ->andWhere(['OR',
- // ['AND',
- // ['<=' , 'pg.start_time', strtotime($this->start_time)],
- // ['>=' , 'pg.end_time',strtotime($this->end_time)]
- // ],
- // ['AND',
- // ['<=' , 'pg.start_time', strtotime($this->start_time)],
- // ['<=' , 'pg.end_time',strtotime($this->end_time)],
- // ['>=' , 'pg.end_time',strtotime($this->start_time)]
- // ],
- // ['AND',
- // ['>=' , 'pg.start_time', strtotime($this->start_time)],
- // ['<=' , 'pg.end_time',strtotime($this->end_time)]
- // ],
- // ['AND',
- // ['>=' , 'pg.start_time', strtotime($this->start_time)],
- // ['>=' , 'pg.end_time',strtotime($this->end_time)],
- // ['<=' , 'pg.start_time',strtotime($this->end_time)]
- // ],
- // ])->andWhere(['pg.is_delete' => 0, 'pag.is_delete' => 0])->select('pag.id, pag.activity_id')->one();
- // if ($is_exist_goods) {
- // throw new \Exception("部分商品已经在其他未开始/进行中的新人专享活动中");
- // }
- if (empty($item['cat_id'])) {
- throw new \Exception("保存失败, 商品" . $Goods->name . '没有选择分类');
- }
- $activity_goods = new PtActivityGoods();
- $activity_goods->goods_id = $item['id'];
- $activity_goods->virtual_sales = (int)$item['virtual_sales'];
- $activity_goods->store_id = get_store_id();
- $activity_goods->use_attr = (int)$Goods->use_attr;
- $activity_goods->sale_num = $sale_num;
- $activity_goods->cat_id = $item['cat_id'];
- if ((int)$Goods->use_attr === 1 && empty($item['attr'])) {
- throw new \Exception("保存失败, 商品" . $Goods->name . '没有规格参数');
- }
- if (is_string($item['attr'])) {
- $item['attr'] = json_decode($item['attr'], true);
- }
- if ((int)$Goods->use_attr === 1 && $item['attr']) {
- foreach ($item['attr'] as $value) {
- if (!isset($value['attr_list']) || !isset($value['pt_price'])) {
- throw new \Exception("保存失败, 商品" . $Goods->name . '规格参数错误');
- }
- if ($value['pt_price'] > $value['price']) {
- throw new \Exception("保存失败, 商品" . $Goods->name . '拼团价需小于售价');
- }
- }
- $activity_goods->attr = json_encode($item['attr']);
- } else {
- $attr = json_decode($Goods->attr, true);
- $attr[0]['pt_price'] = $activity_goods->pt_price = (float)$item['pt_price'];
- $activity_goods->attr = json_encode($attr);
- if ($activity_goods->pt_price > $Goods->price) {
- throw new \Exception("保存失败, 商品" . $Goods->name . '拼团价需小于售价');
- }
- }
- $activity_goods->activity_id = $activity->id;
- if (!$activity_goods->save()) {
- throw new \Exception(json_encode($activity_goods->errors));
- }
- if ($old_goods && ($old_goods->use_attr != $activity_goods->use_attr ||
- $old_goods->cat_id != $activity_goods->cat_id ||
- $old_goods->attr != $activity_goods->attr ||
- $old_goods->pt_price != $activity_goods->pt_price
- )) {
- $open = true;
- }
- } else {
- throw new \Exception("商品未找到或已下架");
- }
- }
- if ($open) {
- $activity->is_platform_audit = 0;
- if (!$activity->save()) {
- throw new \Exception(json_encode($activity->errors, JSON_UNESCAPED_UNICODE));
- }
- }
- //觉得没啥用,直接保存后删除
- PtActivityGoods::deleteAll(['activity_id' => $activity->id, 'is_delete' => 1]);
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '操作成功!'
- ];
- } catch (\Exception $e) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function setStatus ()
- {
- try {
- if ($this->ids) {
- $ids = explode(',', $this->ids);
- if (in_array($this->status, [0, 1])) {
- PtActivity::updateAll(['status' => $this->status], ['id' => $ids, 'store_id' => get_store_id(), 'is_delete' => 0]);
- }
- if ((int)$this->status === 2) {
- PtActivity::updateAll(['is_delete' => 1], ['id' => $ids, 'store_id' => get_store_id(), 'is_delete' => 0]);
- PtActivityGoods::updateAll(['is_delete' => 1], ['activity_id' => $ids, 'store_id' => get_store_id(), 'is_delete' => 0]);
- }
- if (count($ids) === 1) {
- (new DiyCommon)->JobBehaviors(get_store_id(), StoreSyncExtLog::TYPE_PT, $ids);
- }
- } else {
- $rules = PtActivity::findOne(['id' => $this->id, 'is_delete' => 0, 'store_id' => get_store_id()]);
- if (empty($rules)) {
- throw new \Exception("规则不存在");
- }
- if (in_array($this->status, [0, 1])) {
- $rules->status = $this->status;
- }
- if ((int)$this->status === 2) {
- $rules->is_delete = 1;
- }
- if (!$rules->save()) {
- throw new \Exception(json_encode($rules->errors));
- }
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功!'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function getArticle() {
- try {
- $article = AboutArticle::find()->where([
- 'is_delete' => AboutArticle::IS_DELETE_NO,
- 'store_id' => get_store_id(),
- 'type' => 1
- ])->select("desc")->asArray()->one();
- return [
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'desc' => $article['desc']
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function saveArticle() {
- try {
- if (empty($this->desc)) {
- throw new \Exception('规则不能为空');
- }
- $article = AboutArticle::findOne(['store_id' => get_store_id(), 'is_delete' => 0, 'type' => 1]) ?: new AboutArticle();
- $article->name = "拼团规则";
- $article->sort = 1;
- $article->type = 1;
- $article->desc = $this->desc;
- $article->store_id = get_store_id();
- if (!$article->save()) {
- throw new \Exception(json_encode($article->errors));
- }
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- /**
- * 审核列表
- */
- public function auditList() {
- try {
- $query = PtActivity::find()->alias('p')->where(['p.is_delete' => 0, 'is_platform' => 1, 's.is_delete' => 0]);
- $query->leftJoin(['s' => Store::tableName()], 's.id = p.store_id');
- if ($this->store_name) {
- $query->andWhere(['LIKE', 's.name', $this->store_name]);
- }
- if ($this->name) {
- $query->andWhere(['LIKE', 'p.name', $this->name]);
- }
- if ($this->is_platform_audit > -1 && $this->is_platform_audit !== null) {
- $query->andWhere(['p.is_platform_audit' => $this->is_platform_audit]);
- }
- if (intval($this->status) === 1) {//未开始
- $query->andWhere(['AND', ['>' , 'p.start_time', time()], ['status' => 1]]);
- }
- if (intval($this->status) === 2) {//进行中
- $query->andWhere(['AND', ['<' , 'p.start_time', time()], ['>' , 'p.end_time', time()], ['status' => 1]]);
- }
- if (intval($this->status) === 3) { //已结束
- $query->andWhere(['AND', ['<' , 'p.end_time', time()], ['status' => 1]]);
- }
- if (intval($this->status) === 4) { //已终止
- $query->andWhere(['p.status' => 0]);
- }
- //只有平台运营的商城或者单店铺的无独立小程序才展示商盟的营销活动
- if (\Yii::$app->prod_is_dandianpu()) {
- $store_id = Option::find()->where(['group' => 'store', 'name' => 'self_mini'])->select('store_id')->column();
- $query->andWhere(['NOT IN', 's.id', $store_id]);
- } else {
- $query->andWhere(['s.business_model' => 2]);
- }
- if (!empty($this->start_time) && !empty($this->end_time)) { //时间筛选
- $query->andWhere(['OR',
- ['AND',
- ['<=' , 'p.start_time', strtotime($this->start_time)],
- ['>=' , 'p.end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['<=' , 'p.start_time', strtotime($this->start_time)],
- ['<=' , 'p.end_time',strtotime($this->end_time)],
- ['>=' , 'p.end_time',strtotime($this->start_time)]
- ],
- ['AND',
- ['>=' , 'p.start_time', strtotime($this->start_time)],
- ['<=' , 'p.end_time',strtotime($this->end_time)]
- ],
- ['AND',
- ['>=' , 'p.start_time', strtotime($this->start_time)],
- ['>=' , 'p.end_time',strtotime($this->end_time)],
- ['<=' , 'p.start_time',strtotime($this->end_time)]
- ],
- ]);
- }
- $query->select('p.id, p.start_time, p.end_time, p.created_at, p.updated_at, p.name, p.party_type, p.party_goods_count, p.party_size pt_join_num, p.is_platform_audit, p.status, s.name store_name, s.logo, s.id store_id')->orderBy('p.created_at desc');
- $pagination = pagination_make($query);
- foreach ($pagination['list'] as &$item) {
- $item['logo'] = $item['logo'] ?: Option::get(OptionSetting::STORE_LOGO, $item['store_id'], 'store', '')['value'];
- //获取活动状态
- if (intval($item['status']) === 1) {
- if ($item['start_time'] > time()) {
- $item['status'] = 1;
- }
- if ($item['start_time'] < time() && $item['end_time'] > time()) {
- $item['status'] = 2;
- }
- if ($item['end_time'] < time()) {
- $item['status'] = 3;
- }
- } else {
- $item['status'] = 4;
- }
- $item['is_platform_audit'] = (int)$item['is_platform_audit'];
- //格式化时间
- $item['start_time'] = date("Y-m-d H:i:s", $item['start_time']);
- $item['end_time'] = date("Y-m-d H:i:s", $item['end_time']);
- $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- $item['updated_at'] = $item['updated_at'] ? date("Y-m-d H:i:s", $item['updated_at']) : '';
- //计算订单数量 订单金额
- $pt_order = PtActivityOrderDetail::find()->alias('od')->where(['od.activity_id' => $item['id']])
- ->leftJoin(['o' => PtActivityOrder::tableName()], 'od.order_id = o.id')
- ->andWhere(['o.is_winner' => 1])->select('o.total_price')->column();
- $item['pt_order_count'] = count($pt_order); //成团订单数量
- $item['pt_total_price'] = array_sum($pt_order); //订单金额
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $pagination['list'],
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- ]
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- /**
- * 处理审核
- */
- public function auditHandle() {
- try {
- $id = $this->id;
- $status = $this->status;
- $pt_activity = PtActivity::findOne(['id' => $id, 'is_platform' => 1, 'is_delete' => 0]);
- if (!$pt_activity) {
- throw new \Exception('活动不存在');
- }
- if (in_array($status, [1, 2])) {
- if (intval($pt_activity->is_platform_audit) !== 0) {
- throw new \Exception('活动已经审核');
- }
- $pt_activity->is_platform_audit = $status;
- }
- if (intval($status) === 3) {
- $pt_activity->is_delete = 1;
- }
- if (in_array($status, [4, 5])) {
- $pt_activity->status = intval($status - 4);
- }
- if (!$pt_activity->save()) {
- throw new \Exception(json_encode($pt_activity->errors, JSON_UNESCAPED_UNICODE));
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- }
|