| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /**
- * Created by PhpStorm
- * Author: 向往那片天空
- * Date: 2020/6/9
- * Time: 9:07
- * 微信/QQ: 250023777
- * 格言: 抓住中心,宁精勿杂,宁专勿多
- */
- namespace app\models\store;
- use app\admin\model\order\StoreOrder;
- use app\admin\model\store\StoreProductAttrValue;
- use crmeb\basic\BaseModel;
- use crmeb\services\PHPExcelService;
- use crmeb\traits\ModelTrait;
- class StoreTryProduct extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'store_try_product';
- use ModelTrait;
- public static function validWhere()
- {
- return self::where('is_del', 0);
- }
- /**
- * 获取试用数据
- * @param int $page
- * @param int $limit
- * @return mixed
- */
- public static function getAll($page = 0, $limit = 20)
- {
- $time = time();
- $model = new self();
- $model = $model->alias('t');
- $model = $model->join('store_product s', 's.id=t.product_id');
- $model = $model->field('t.*,s.stock,s.price');
- $model = $model->order('t.sort desc,t.id desc');
- $model = $model->where('t.is_show', 1);
- $model = $model->where('t.is_del', 0);
- // $model = $model->where('t.is_finish', 0);
- // $model = $model->where('t.start_time', '<', $time);
- // $model = $model->where('t.stop_time', '>', $time);
- if ($page) $model = $model->page($page, $limit);
- return $model->select()->each(function ($item) {
- $item['image'] = set_file_url($item['image']);
- });
- }
- /**
- * 获取一条试用商品数据
- * @param $id
- * @return mixed
- */
- public static function getTryOne($id)
- {
- $model = new self();
- $model = $model->alias('t');
- $model = $model->join('store_product s', 's.id=t.product_id');
- // $model = $model->field('a.*,s.price as product_price,SUM(s.sales+s.ficti) as total');
- $model = $model->field('t.*,s.slider_image,s.stock,s.unit_name,s.price');
- $model = $model->where('t.is_show', 1);
- $model = $model->where('t.is_del', 0);
- // $model = $model->where('t.is_finish', 0);
- $model = $model->where('t.id', $id);
- // $model = $model->where('a.start_time','<',time());
- // $model = $model->where('a.stop_time','>',time()-86400);
- return $model->find();
- }
- /**
- * 修改销量和库存
- * @param $num
- * @param $CombinationId
- * @return bool
- */
- public static function decCombinationStock($num, $product_id, $unique)
- {
- if ($unique) {
- $res = false !== StoreProductAttrValue::decProductAttrStock($product_id, $unique, $num, 0);
- // $res = $res && self::where('id', $CombinationId)->dec('stock', $num)->inc('sales', $num)->update();
- $sku = StoreProductAttrValue::where('product_id', $product_id)->where('unique', $unique)->where('type', 0)->value('suk');
- $res = $res && StoreProductAttrValue::where('product_id', $product_id)->where('suk', $sku)->where('type', 0)->dec('stock', $num)->inc('sales', $num)->update();
- } else {
- $res = $res && StoreProduct::where('id', $product_id)->dec('stock', $num)->inc('sales', $num)->update();
- }
- return $res;
- }
- }
|