cxfoot/modules/api/models/ActivityForm.php
2023-10-24 14:54:18 +08:00

147 lines
4.1 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021-5-17
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\models;
use app\models\Activity;
use function AlibabaCloud\Client\value;
use app\components\SysConst;
use app\models\common\payment\PaymentOrder;
use app\components\SiteHelper;
use app\models\Detection;
use app\models\Goods;
use app\models\Model;
use app\models\Order;
use app\models\OrderDetail;
use app\models\PaymentTypes;
use app\models\Store;
use app\models\UniqueOrderNo;
use app\models\User;
use app\models\UserBallArm;
use app\modules\api\components\ApiHelper;
use app\modules\api\components\GetDistance;
use yii\data\Pagination;
class ActivityForm extends ApiModel
{
public $user_id;
public $cx_mch_id;
public $page;
public $limit;
public $store_id; # 门店id
public $title; # 球杆名称
public $data;
public $id;
public $type;
public $order_id;
public function rules()
{
return [
[['title'], 'trim'],
[['title', 'data'], 'string'],
[['user_id', 'page', 'limit', 'store_id', 'id', 'type', 'order_id'], 'integer'],
// [['user_id', 'cx_mch_id'], 'required'],
];
}
/**
* showdoc
* @catalog 活动
* @title 获取最新活动
* @description 本接口提供获取最新活动
* @method get
* @url /api/default/get-activity
* @return {"code":0,"msg":"ok","data":[]}
* @remark
*/
public function actionGetActivity(){
$data = Activity::find()
->andWhere([
'status' => 1,
'is_delete' => 0,
])
->select('id,name,start_time,end_time,poster_img_arr,poster_btn_name,poster_btn_url')
->asArray()
->all();
if(empty($data)){
return $this->apiReturnSuccess('ok',[]);
}
$res = [];
foreach ($data as $key=>$val){
if($val['start_time'] > time() || $val['end_time'] < time()){
continue;
}
if(empty($val['poster_img_arr'])){
continue;
}
$val['poster_img_arr'] = json_decode($val['poster_img_arr'],true);
if(empty($val['poster_img_arr'])){
continue;
}
if(count($val['poster_img_arr']) == 1){
$val['poster_img_arr'] = SiteHelper::getFullUrl($val['poster_img_arr'][0]);
}else{
$tmp_data = [];
foreach ($val['poster_img_arr'] as $k=>$v){
$tmp_data[] = SiteHelper::getFullUrl($v);
}
$val['poster_img_arr'] = $tmp_data;
}
$val['start_date'] = date('Y-m-d H:i',$val['start_time']);
$val['end_date'] = date('Y-m-d H:i',$val['end_time']);
$res[] = $val;
}
return $this->apiReturnSuccess('ok',$res);
}
/**
* showdoc
* @catalog 活动
* @title 获取活动详情
* @description 本接口提供获取活动详情
* @method get
* @url /api/default/get-activity-info
* @remark
*/
public function actionGetActivityInfo(){
if(empty($this->id)){
return $this->apiReturnError('暂无活动');
}
$find = Activity::findOne([
'id' => $this->id,
'is_delete' => 0,
'status' => 1,
]);
if(empty($find)){
return $this->apiReturnError('暂无活动');
}
$res = [
'name' => $find->name,
'content' => $find->content,
'start_time' => $find->start_time,
'end_time' => $find->end_time,
'start_date' => date('Y-m-d H:i:s',$find->start_time),
'end_date' => date('Y-m-d H:i:s',$find->end_time),
'content_btn_name' => $find->content_btn_name,
'content_btn_url' => $find->content_btn_url,
];
return $this->apiReturnSuccess('ok',$res);
}
}