1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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('order_refund_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],['status','=',2]])->update(['status'=>1]);
- }
- //获取当月日历
- function get_month_days(){
- $date = date('Y-m-d');
- $start_time = strtotime($date);
- $total_month_day = date('t', $start_time);// 当月天数
- $month_data = [];
- $base_data = date("Y-m");
- for($i=1;$i<=$total_month_day;$i++) {
- $c = $i;
- if($c < 10) $c ='0'.$i;
- $month_data[] = [
- 'date_str'=>$base_data.'-'.$c,
- 'date' => $i,
- 'prefix_date' => $c,
- 'week' => date('w',strtotime($base_data.'-'.$c))
- ];
- }
- return $month_data;
- }
|