File: /var/www/dk/wp-content/themes/food/Business/PostTryLearnBs.php
<?php
//课程试看
namespace Business;
use ApiErrorDesc;
use PostTryLearnModel;
class PostTryLearnBs
{
public $dbObj = null;
public function __construct()
{
$this->dbObj = new PostTryLearnModel();
}
public function setPostTryLearn($data, $debug = false)
{
$outObj = new stdClass();
$outObj->rc = ApiErrorDesc::ERR_DONE[0];
$outObj->msg = ApiErrorDesc::ERR_DONE[1];
$action = $data['action'];
$inData = $data;
if ($debug) {
print_r($inData);
}
$res = false;
if ($action == 'del') {
$res = $this->dbObj->delPostTryLearn($inData, $debug);
} else {
if ($action == 'update') {
$infoCount = $this->dbObj->getCountCommon2($this->dbObj->tableName, 'post_id', $data['post_id'], "1", "1", $debug);
if ($infoCount == 0) {
$action = 'add';
} else {
$action = 'updateByPostId';
}
}
$inData['status'] = '1';
$res = $this->dbObj->setPostTryLearn($action, $inData, $debug);
}
if ($res) {
$outObj->rc = ApiErrorDesc::SUCCESS[0];
$outObj->msg = ApiErrorDesc::SUCCESS[1];
}
return $outObj;
}
public function getInfoByPage($where, $data, $debug)
{
// $debug = $data['debug'];
// $where = [];
// if (isset($data['id'])) {
// $where['id'] = $data['id'];
// }
$infoCount = $this->dbObj->getCountByPage($where, $data, $debug);
// echo '$infoCount ' . $infoCount;
$outputArr = [];
if ($infoCount > 0) {
$infoArr = $this->dbObj->getInfoByPage($where, $data, $debug);
$outputArr = $this->outPutFunc($infoArr, $data, $debug);
}
$outObj = new stdClass();
$outObj->rc = ApiErrorDesc::ERR_NODATA[0];
$outObj->msg = ApiErrorDesc::ERR_NODATA[1];
$outObj->total = strval($infoCount);
if ($infoCount > 0) {
$outObj->rc = ApiErrorDesc::SUCCESS[0];
$outObj->msg = ApiErrorDesc::SUCCESS[1];
}
$outObj->pageNum = strval($where['pageNum']);
$outObj->pageSize = strval($where['pageSize']);
$outObj->dataList = $outputArr;
return $outObj;
}
public function outPutFunc($infoArr, $data, $debug = false)
{
// if ($debug) {
// print_r($infoArr);
// }
//`id`, `series_id`, `post_id`, `type`, `try_time`, `mtime`, `status`
$outputArr = array();
if (count($infoArr) > 0) {
foreach ($infoArr as $item => $value) {
$itemArr = array(
'id' => strval($value->id),
'series_id' => strval($value->series_id),
'post_id' => strval($value->post_id),
'type' => strval($value->type),
'try_time' => strval($value->try_time),
'mtime' => strval($value->mtime),
'mtime2' => $value->mtime2,
);
$outputArr[] = $itemArr;
}
// print_r($outputArr);
}
return $outputArr;
}
/**
* 通过post_id 数组 获取 试看
* @param $where
* @param $postIdArr
* @param $data
* @param false $debug
* @return array
*/
public function getInfoINPostIdArr($where, $postIdArr, $data, $debug = false)
{
$idArr = array_unique($postIdArr);
$idlist = implode(',', $idArr);
global $wpdb;
$sql = "SELECT * FROM `xt_post_try_learn` WHERE {$where} IN ({$idlist}) ";
if ($debug) {
echo '<br>' . $sql;
}
// $re = $wpdb->get_results($sql, 'ARRAY_A');
$re = $wpdb->get_results($sql);
$liveArr = $this->outputFunc($re, $data, $debug);
// print_r($liveArr);
$outArr = [];
foreach ($liveArr as $item => $value) {
$outArr[$value['post_id']] = $value;
}
return $outArr;
}
}