123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * GoodsLogic.php UTF-8
- * 商品逻辑处理
- *
- * @date : 2018/5/7 22:49
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\shop;
- use huo\model\common\CommonModel;
- use huo\model\shop\GoodsModel;
- use huolib\status\ShopStatus;
- class GoodsLogic extends CommonModel {
- protected $base_field
- = [
- 'id' => 'goods_id',
- 'goods_name' => 'goods_name',
- 'is_real' => 'is_real',
- 'store_cnt' => 'total_cnt',
- 'remain_cnt' => 'remain_cnt',
- 'mem_times' => 'mem_times',
- 'market_price' => 'market_price',
- 'goods_intro' => 'goods_intro',
- 'initial' => 'initial',
- 'original_img' => 'original_img',
- 'integral' => 'integral',
- 'gain_integral' => 'gain_integral',
- 'object_type' => 'object_name',
- 'object_id' => 'object_id',
- 'flag' => 'flag',
- ];
- /**
- * 获取商品列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @param array $field
- * @param bool $_base
- *
- * @return int| array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList($where = [], $page = '1,10', $order = '', $field = [], $_base = true) {
- $_goods_model = new GoodsModel();
- $_count = $_goods_model->useGlobalScope($_base)->where($where)->count();
- if (empty($_count)) {
- return ShopStatus::GOODS_CNT_ZERO;
- }
- $_field = $this->base_field;
- $_field = array_merge($_field, $field);
- $_order = $this->orderFilter($order);
- $_goodss = $_goods_model
- ->useGlobalScope($_base)
- ->field($_field)
- ->where($where)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_goodss)) {
- $_goodss = $_goodss->toArray();
- }
- if (empty($_goodss)) {
- $_list = null;
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- $_list = [];
- foreach ($_goodss as $_k => $_v) {
- $_data = [];
- $_data['goods_id'] = $_v['goods_id'];
- $_data['goods_name'] = $_v['goods_name'];
- $_data['is_real'] = $_v['is_real'];
- $_data['total_cnt'] = $_v['total_cnt'];
- $_data['remain_cnt'] = $_v['remain_cnt'];
- $_data['market_price'] = $_v['market_price'];
- $_data['goods_intro'] = $_v['goods_intro'];
- $_data['initial'] = $_v['initial'];
- $_data['original_img'] = $_v['original_img'];
- $_data['integral'] = $_v['integral'];
- $_data['gain_integral'] = $_v['gain_integral'];
- $_data['object_name'] = $_v['object_name'];
- $_data['object_id'] = $_v['object_id'];
- $_data['flag'] = $_v['flag'];
- if (isset($_v['is_on_sale'])) {
- $_data['is_on_sale'] = $_v['is_on_sale'];
- }
- if (isset($_v['on_time'])) {
- $_data['on_time'] = $_v['on_time'];
- }
- if (isset($_v['update_time'])) {
- $_data['update_time'] = $_v['update_time'];
- }
- if (isset($_v['list_order'])) {
- $_data['list_order'] = $_v['list_order'];
- }
- $_list[] = $_data;
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- /**
- * 通过商品ID 查询商品信息
- *
- * @param $goods_id
- *
- * @return array|bool|false
- */
- public function getInfoByGoodsId($goods_id) {
- if (empty($goods_id)) {
- return false;
- }
- $_map['id'] = $goods_id;
- $_field = $this->base_field;
- $_field['goods_content'] = 'goods_content';
- $_goods_data = (new GoodsModel())->useGlobalScope(false)->field($_field)->where($_map)->find();
- if (is_object($_goods_data)) {
- $_goods_data = $_goods_data->toArray();
- }
- return $_goods_data;
- }
- }
|