135 lines
4.1 KiB
PHP
135 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\admin\models\ball;
|
|
|
|
use app\components\SysConst;
|
|
use app\models\Order;
|
|
use app\models\Store;
|
|
use app\models\StoreEarnings;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use yii\data\Pagination;
|
|
|
|
class BallMarkEditForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
|
|
public $keywords;
|
|
public $status;
|
|
public $store_id;
|
|
|
|
|
|
public $model;
|
|
|
|
public $name;
|
|
public $desc;
|
|
|
|
public $created_at;
|
|
public $updated_at;
|
|
public $is_delete;
|
|
public $deleted_at;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords',], 'string'],
|
|
[['page', 'limit', 'status', 'store_id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
|
|
[['name'], 'required'],
|
|
[['desc'], 'string'],
|
|
[['is_delete', 'created_at', 'updated_at', 'deleted_at', 'status'], 'integer'],
|
|
[['name'], 'string', 'max' => 50],
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$query = StoreEarnings::find()->alias('se')
|
|
->select('se.id,se.money,u.nickname,s.name as store_name,o.order_no,o.total_price,o.plugin_sign')
|
|
->leftJoin(['u' => User::tableName()], 'se.user_id=u.id')
|
|
->leftJoin(['s' => Store::tableName()], 'se.store_id=s.id')
|
|
->leftJoin(['o' => Order::tableName()], 'se.order_id=o.id')
|
|
->where([
|
|
'se.is_delete' => 0
|
|
])
|
|
->andFilterWhere(['se.status' => $this->status])
|
|
->andFilterWhere(['se.store_id' => $this->store_id])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like', 's.name', $this->keywords],
|
|
['like', 'u.username', $this->keywords],
|
|
['like', 'o.order_no', $this->keywords],
|
|
]);
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['se.created_at' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item) {
|
|
$item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);
|
|
$item['updated_at_cn'] = '未发放';
|
|
if (!empty($item['updated_at'])) {
|
|
$item['updated_at_cn'] = date("Y-m-d H:i", $item['updated_at']);
|
|
}
|
|
if ($item['plugin_sign'] == SysConst::$cxPluginSceneBallArmMall) {
|
|
$item['plugin_sign_cn'] = '球杆检测';
|
|
} elseif ($item['plugin_sign'] == SysConst::$cxPluginSceneHitBallMall) {
|
|
$item['plugin_sign_cn'] = '击球检测';
|
|
} elseif ($item['plugin_sign'] == SysConst::$cxPluginSceneMemberMall) {
|
|
$item['plugin_sign_cn'] = '会员购买';
|
|
}
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
if ($this->model->isNewRecord) {
|
|
$this->model->is_delete = 0;
|
|
$this->model->deleted_at = 0;
|
|
$this->model->created_at = time();
|
|
}
|
|
$this->model->name = $this->name;
|
|
$this->model->updated_at = time();
|
|
if ($this->desc) {
|
|
$this->model->desc = $this->desc;
|
|
}
|
|
if ($this->status) {
|
|
$this->model->status = $this->status;
|
|
}
|
|
if (!$this->model->save()) {
|
|
return $this->getModelError($this->model);
|
|
}
|
|
return $this->apiReturnSuccess('保存成功');
|
|
}
|
|
|
|
|
|
} |