$user_id, 'type_id' => $type_id, 'content' => $content, 'create_at' => date('Y-m-d H:i:s'), ]; Db::table('user_message')->insert($msg_data); return Db::getLastInsID(); } function goods_sell_info($goods_info,$user_id,$from_id = 0) { $sell_info =[ 'goods_id'=>$goods_info['id'], 'goods_type'=>$goods_info['type'], 'user_id'=>$user_id, 'year'=> date('Y'), 'month'=> date('m'), 'day'=> date('d'), 'from_id'=> $from_id, 'goods_info'=>json_encode($goods_info) ]; Db::table('goods_sell_info')->insert($sell_info); } /** * 获取商品hash值 * @param $user_id 用户id * @param $name 商品id * @param $count 收藏数量 * @return string */ function get_goods_hash($user_id,$name='',$count = 0){ $host = "http://101.200.81.225:9090/contract/call"; //$host = "http://jc.nfrcn.vip:9090/contract/call"; $method = "POST"; $headers = array(); array_push($headers, "Content-Type".":"."application/json; charset=UTF-8"); $bodys = [ 'key' => 'JDchinahgsc20220035', 'userkey' =>$user_id, 'product' => json_encode(['name'=>$name,'count'=>$count]) ]; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $host); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys)); $res = curl_exec($curl); if(!$res) return ['hash_str'=>'']; $hash_res = json_decode($res,true); return [ 'hash_str'=> isset($hash_res['code']) && $hash_res['code'] == 200 ? $hash_res['data']['contentHash']:'',// 哈希 ]; } /** * 获取系统配置 * @param $array * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function getConfig($array){ $set = Db::table('system_config')->where('name','in',$array)->select(); $ret = []; foreach ($set as $value) { $ret[$value['name']]=$value['value']; } return $ret; } /** * @title 取消订单定时任务 * @desc 十五分钟内未支付的自动取消 */ function cancel_goods_order($user_id = 0) { $set_time = intval(sysconf('cancel_time')) ? : 5;// 没设置默认5分钟未支付的自动取消 $sel_time = time() - $set_time * 60 ; $where = []; $where[] = ['create_at','< time',date('Y-m-d H:i:s',$sel_time)]; $where[] = ['status','=',0]; $where[] = ['cancel_state','=',0]; if($user_id) $where[] = ['uid','=',$user_id]; $order_data = Db::table('goods_order') ->where($where) ->select(); foreach ($order_data as $order_info) { Db::startTrans(); try { Db::table('goods_order')->where(['id'=>$order_info['id']]) ->update(['status'=>9,'cancel_state'=>1,'cancel_at'=>date('Y-m-d H:i:s'),'cancel_desc'=>'支付超时!自动取消']); Db::table('store_goods')->where('id', $order_info['goods_id']) ->setInc('stock', $order_info['goods_num']); Db::commit(); }catch (\Exception $e){ Db::rollback(); } } }