HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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;
    }
}