<?php
class product extends base
{
  /**
   * [cids 主要获取下拉框内的分类]
   * @Author   huangxiaojian
   * @DateTime 2021-04-30T09:49:16+0800
   * @param    integer                  $pid      [上级ID]
   * @param    integer                  $model_id [模型ID]
   * @return   [type]                             [description]
   */
  function listwhere($where)
  {
    if ($_POST['cid']) {
      $where .= " and cid=" . $_POST['cid'];
    }
    if ($_POST['tj']) {
      $where .= " and tj=" . $_POST['tj'];
    }
    if ($_POST['status']) {
      $where .= " and status=" . $_POST['status'];
    }
    if ($_POST['id']) {
      $where .= " and id=" . $_POST['id'];
    }
    return $where;
  }
  public function cids($pid = 0, $status = 0)
  {
    if ($status > 0)
      $where = "status=$status";
    else
      $where = "1=1";
    $order = $_POST['order'] != '' ? $_POST['order'] : 'asc';
    $data = db()->select_all("product_type", "id, title, pid", $where . ' order by sort ' . $order . ', id desc');
    $res = reSort($data, $pid, 0, TRUE);
    $arr = [];
    foreach ($res as $key => $value) {
      $arr[$value['id']] = $value['title'];
    }
    return $arr;
  }
  public function list($list)
  {
    foreach ($list as $key => $value) {
      $list[$key]['cname'] = db()->select('product_type', "title", 'id=' . $value['cid']);
      $list[$key]['body'] = strip_tags($value['content']);
      if ($value['qrcode']) {
        $list[$key]['qrcode'] = xcx_img($value['qrcode']);
      }
    }
    return $list;
  }
}
