123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- // 接口公共方法
- use think\Db;
- // 更新商品库存
- function update_goods_stock($goods_id,$goods_no,$num){
- $goods_info = Db::table('store_goods')
- ->field('id,spec,stock')
- ->where(['id'=>$goods_id])
- ->find();
- $spec = json_decode($goods_info['spec'],true);
- foreach ($spec as $gk=>&$gv) {
- if($gv['goods_no'] == $goods_no) {
- $spec[$gk]['store_num'] = bcsub($gv['store_num'],$num) > 0 ? bcsub($gv['store_num'],$num) : 0;
- }
- }
- $stock = $goods_info['stock']-$num >0 ? $goods_info['stock']-$num:0;
- return Db::table('store_goods')->where(['id'=>$goods_id])->update(['spec'=>json_encode($spec),'stock'=>$stock]);
- }
- // 获取商品规格详情
- function get_goods_spec($goods_id,$goods_no)
- {
- $goods_spec = [];
- $goods_info = Db::table('store_goods')->field('id,spec,stock')->find($goods_id);
- if(empty($goods_info)) return $goods_spec;
- $spec = json_decode($goods_info['spec'],true);
- foreach ($spec as $gk=>$gv) {
- if($gv['goods_no'] == $goods_no) {
- $goods_spec = $gv;
- }
- }
- return $goods_spec;
- }
- // 获取退款理由
- function get_refund_cause()
- {
- $list = Db::table('store_order_cause')
- ->field('id,title')
- ->where(['status'=>1])
- ->order('sort desc , id asc')
- ->select();
- return $list;
- }
- // 更新直播状态
- function change_live_status()
- {
- $date_str = date("Y-m-d H:i:s");
- // 将活动改为进行中状态
- Db::table('store_live')->where([['start_at','< time',$date_str],['end_at','> time',$date_str],['status','=',2]])->update(['status'=>1]);
- // 将活动改为过期状态
- Db::table('store_live')->where([['end_at','< time',$date_str]])->update(['status'=>3]);
- }
|