作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

课程购买次数

... ... @@ -3,6 +3,7 @@
namespace app\admin\controller\mobile\course;
use app\common\controller\Backend;
use think\Db;
/**
* 精品课程管理
... ... @@ -53,20 +54,20 @@ class Course extends Backend
$total = $this->model
->where($where)
->order('is_top desc')
->order(['is_top' => 'desc','top_time' => 'desc', 'createtime' => 'desc'])
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order('is_top desc')
->order(['is_top' => 'desc','top_time' => 'desc', 'createtime' => 'desc'])
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','title','cover','current_price','original_price','study_num_rate','study_num_real','teacher_avatar','teacher_name','teacher_desc','is_top']);
$row->visible(['id','title','cover','current_price','original_price','study_num_rate','study_num_real','teacher_avatar','teacher_name','teacher_desc','is_top','pay_times']);
}
$list = collection($list)->toArray();
... ... @@ -77,6 +78,45 @@ class Course extends Backend
return $this->view->fetch();
}
/**
* 置顶
*/
public function top($ids = null)
{
if($ids) {
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
$params = $this->request->param();
$params['top_time'] = $params['is_top'] == '1' ? time() : 0;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('操作失败');
}
$this->success('操作成功');
}
}
public function selectpage()
{
return parent::selectpage(); // TODO: Change the autogenerated stub
... ...
... ... @@ -18,5 +18,6 @@ return [
'Is_top 1' => '是',
'Top_time' => '置顶时间',
'Createtime' => '创建时间',
'Updatetime' => '修改时间'
'Updatetime' => '修改时间',
'Pay_times' => '购买次数'
];
... ...
... ... @@ -81,7 +81,7 @@ class Course extends Api
$page_num = $this->request->param('page_num', 10, 'intval');
switch ($order) {
case 0:
$order = ['is_top' => 'desc','top_time' => 'desc'];
$order = ['is_top' => 'desc','top_time' => 'desc', 'createtime' => 'desc'];
break;
case 1:
$order = ['study_num_rate' => 'desc'];
... ...
... ... @@ -44,6 +44,8 @@ class Notify extends Api
$order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 购买次数加1
Db::name('mobile_course')->where('id',$order['course_id'])->setInc('pay_times');
}
} catch (Exception $e) {
}
... ...