| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?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 StoreLiveProduct extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'store_live_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($title = '', $page = 0, $limit = 20)
- {
- $model = new self();
- $model = $model->alias('a');
- $model = $model->join('StoreProduct s', 's.id=a.product_id');
- $model = $model->field('a.*,s.price as product_price,s.ficti');
- $model = $model->order('a.sort desc,a.id desc');
- $model = $model->where('a.title', 'like', '%' . $title . '%');
- $model = $model->where('a.is_show', 1);
- $model = $model->where('a.is_del', 0);
- 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 getLiveOne($id)
- {
- $model = new self();
- $model = $model->alias('a');
- $model = $model->join('StoreProduct s', 's.id=a.product_id');
- // $model = $model->field('a.*,s.price as product_price,SUM(s.sales+s.ficti) as total');
- $model = $model->field('a.*,s.price as product_price,s.ficti');
- $model = $model->where('a.is_show', 1);
- $model = $model->where('a.is_del', 0);
- $model = $model->where('a.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, $CombinationId, $unique)
- {
- $product_id = self::where('id', $CombinationId)->value('product_id');
- if ($unique) {
- $res = false !== StoreProductAttrValue::decProductAttrStock($CombinationId, $unique, $num, 5);
- $res = $res && self::where('id', $CombinationId)->dec('stock', $num)->inc('sales', $num)->update();
- $sku = StoreProductAttrValue::where('product_id', $CombinationId)->where('unique', $unique)->where('type', 5)->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 = false !== self::where('id', $CombinationId)->dec('stock', $num)->inc('sales', $num)->update();
- $res = $res && StoreProduct::where('id', $product_id)->dec('stock', $num)->inc('sales', $num)->update();
- }
- return $res;
- }
- }
|