123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103 |
- <?php
- namespace app\admins\service;
- use app\admins\model\Admin as ModelUserAdmin;
- use app\admins\model\StoreBox as StoreBoxModel;
- use app\admins\model\Product as ProductModel;
- use think\Cache;
- use think\Cookie;
- use think\Db;
- //服务工具类
- class Common
- {
- public $show_error = "";
- //获取管理员拥有门店
- static function getStores()
- {
- $model = new StoreBoxModel();
- return $model->getList('store', 'status = 1', 'id ,name');
- }
- /**
- * 获取门店包厢分类
- * @param null $stoId
- * @param null $customer @按客服端显示
- * @return array
- */
- static function stoBoxTypes($stoId = null, $customer = null)
- {
- $model = new StoreBoxModel();
- if ($stoId) {
- $where = "sto_id = {$stoId}";
- } else {
- $where = "id > 0";
- }
- if ($customer) {
- $where .= ' and status = 1 and show_scope in (1, 2)';
- }
- $list = $model->getList('store_box_type', $where, 'id, name');
- $bt = [];
- if (!empty($list)) {
- $bt = array_column($list, 'name', 'id');
- }
- return $bt;
- }
- //获取区域信息
- static function getRegionAddress($pid)
- {
- $model = new ModelUserAdmin();
- return $model->getList('china_region', "code != 0 and pid = {$pid}", null, 'id asc');
- }
- //获取省市区域指定字段
- static function getPCA($pid)
- {
- $model = new ModelUserAdmin();
- return $model->getList('china_region', "code != 0 and pid = {$pid}", 'code, name', 'id asc');
- }
- //日志类型
- const LOG_ADD = 1; //添加
- const LOG_REMOVE = 2;//删除
- const LOG_UPDATE = 3;//更新
- const LOG_LOGIN = 4;//登录
- const LOG_EXIT = 5;//退出
- //获取日志描述
- static function logOptTxt()
- {
- return [
- self::LOG_ADD => '添加',
- self::LOG_REMOVE => '删除',
- self::LOG_UPDATE => '更新',
- self::LOG_LOGIN => '登录',
- self::LOG_EXIT => '退出',
- ];
- }
- /*
- * 添加日志
- * $tableName 表名
- * $type 类型 (1.添加 2.删除 3.修改 4.登录 5退出)
- * $content 操作描述id+其它
- * $details 详情数据
- * $column 操作栏目
- * */
- static function addOperation($tableName, $type, $content = false, $details = null, $column = null)
- {
- $data = array(
- "tb_name" => $tableName,
- "type" => $type,
- "column" => $column,
- "content" => $content,
- "details" => $details,
- "adm_id" => Cookie::get('admin_id'),
- "dt" => date('Y-m-d H:i:s'),
- "ip" => $_SERVER['REMOTE_ADDR'],
- );
- if (!file_exists('journal')) {
- mkdir('journal', 0777, true);
- }
- $str = json_encode($data);
- $day = 'journal/' . date("Y-m-d");
- file_put_contents($day, $str . "^", FILE_APPEND);
- }
- //记录管理员操作日志
- static function logs($content)
- {
- $model = new ModelUserAdmin();
- $data['adm_id'] = Cookie::get('admin_id');
- $data['opera_content'] = $content;
- $data['ip'] = $_SERVER['REMOTE_ADDR'];
- $data['execute_time'] = date('Y-m-d H:i:s');
- $model->addUpdate("admin_log", $data);
- }
- /**
- * 分解时间段
- * @param $staTime @开始时间
- * @param $endTime @结束时间
- * @param $hour @时间划分单位
- * @return array
- */
- static function splitTimeInt($staTime, $endTime, $hour)
- {
- $staTimeTime = strtotime($staTime);
- $entTimeTime = strtotime($endTime);
- $timeSlot = $hour * 3600;
- $pakNum = ceil(($entTimeTime - $staTimeTime) / $timeSlot);
- //小时包计算
- $pakData = [];
- $basLoop = $staTimeTime;
- while ($pakNum) {
- $data['s'] = date('Y-m-d H:i', $basLoop);
- $basLoop = $basLoop + $timeSlot;
- $data['e'] = date('Y-m-d H:i', $basLoop);
- $data['h'] = $hour;
- $data['u'] = 1;
- $data['t'] = 4;
- $pakData[] = $data;
- $pakNum--;
- }
- return $pakData;
- }
- /**
- * 获取门店包厢欢唱时间段
- * @param $stoId @门店id
- * @param $selDate @选择日期
- * @return array
- */
- static function boxTimeInt($stoId, $selDate)
- {
- //获取门店包厢设定小时段
- $model = new \app\admins\model\Common();
- $result = $model->getFind('set_bao_reserve', "shop_id = {$stoId} and genre = 4 and status = 1 and del_status = 1",
- 'start, finish, hour');
- if (empty($result['start']) || empty($result['finish']) || empty($result['hour'])) {
- return null;
- }
- $staTime = $selDate . ' ' . $result['start'];
- $endTime = $selDate . ' ' . $result['finish'];
- $staTimeTime = strtotime($staTime);
- $entTimeTime = strtotime($endTime);
- //结束时间改为第二天
- if ($entTimeTime < $staTimeTime) {
- $entTimeTime = $entTimeTime + 86400;
- }
- $timeSlot = $result['hour'] * 3600;
- $pakNum = floor(($entTimeTime - $staTimeTime) / $timeSlot);
- //小时包计算
- $pakData = [];
- $basLoop = $staTimeTime;
- while ($pakNum) {
- $data['s'] = date('Y-m-d H:i', $basLoop);
- $basLoop = $basLoop + $timeSlot;
- $data['e'] = date('Y-m-d H:i', $basLoop);
- $data['h'] = $result['hour'];
- $data['u'] = 1;
- $data['t'] = 4;
- $pakData[] = $data;
- $pakNum--;
- }
- return $pakData;
- }
- /**
- * 获取门店包厢欢唱包场时间段
- * @param $stoId @门店id
- * @param $selDate @选择时间
- * @param $allField @获取所以时段
- * @return array
- */
- static function boxWholeInt($stoId, $selDate = null, $allField = 0)
- {
- $model = new \app\admins\model\Common();
- if($allField){
- $list = $model->getList('set_bao_reserve', "shop_id = {$stoId}", 'alias, price, hour, genre, start, finish ', 'genre asc');
- }else{
- $list = $model->getList('set_bao_reserve', "shop_id = {$stoId} and genre != 4 and status = 1 and del_status = 1",
- 'alias, price, hour, genre, start, finish ', 'genre asc');
- }
- $bcTimeSlot = [];
- foreach ($list as $k => $v) {
- //包场名称
- if ($v['genre'] == 1) {
- $cd['n'] = $v['alias'] ? $v['alias'] : '上午场';
- } else if ($v['genre'] == 2) {
- $cd['n'] = $v['alias'] ? $v['alias'] : '下午场';
- } else if ($v['genre'] == 3) {
- $cd['n'] = $v['alias'] ? $v['alias'] : '全天场';
- }
- //开始时间
- $cd['s'] = substr($selDate . ' ' . $v['start'], 0, 16);
- //结束时间
- $cd['e'] = substr($selDate . ' ' . $v['finish'], 0, 16);
- //获取小时数
- $s = strtotime($cd['s']);
- $e = strtotime($cd['e']);
- if ($s > $e) {
- $cd['e'] = date('Y-m-d H:i', strtotime($cd['e']) + 86400);
- }
- //欢唱时段
- $cd['h'] = self::getHour(strtotime($cd['e']) - strtotime($cd['s']));
- $cd['u'] = 1;
- //场次
- $cd['t'] = $v['genre'];
- $bcTimeSlot[] = $cd;
- }
- return $bcTimeSlot;
- }
- static function getHour($time)
- {
- return $time / 3600;
- }
- //返回小时数
- /**
- * 获取可预定包厢时段
- * @param $array1 @门店包厢时段
- * @param $array2 @门店包厢预定时段
- * @param $selDate @选择查询日期
- * @return mixed
- */
- static function flagRepeatArray($array1, $array2, $selDate, $timeWay)
- {
- $today = date('Y-m-d');
- $now = time();
- //选择昨天以前
- if ($today > $selDate) {
- foreach ($array1 as $k => $v) {
- $array1[$k]['u'] = 0;
- }
- } else {
- foreach ($array1 as $k => $v) {
- //查询今天
- $boxTime = strtotime($today . ' ' . $v['s']);
- if (($today == $selDate) && ($now > $boxTime)) {
- $array1[$k]['u'] = 0;
- } else {
- foreach ($array2 as $k1 => $v1) {
- $st = $selDate . ' ' . $v['s'] . ':00';
- $st = substr($st, 0, 19);
- $et = $selDate . ' ' . $v['e'] . ':00';
- $et = substr($et, 0, 19);
- if ($timeWay) {//包场判断
- if (($v1['s'] >= $st) && ($v1['s'] < $et)) {
- $array1[$k]['u'] = 0;
- }
- } else {//自由判断
- if (($st == $v1['s'])) {
- $array1[$k]['u'] = 0;
- }
- }
- }
- }
- }
- }
- return $array1;
- }
- //获取毫秒时间戳
- static function getMillisecond()
- {
- list($t1, $t2) = explode(' ', microtime());
- return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
- }
- //生成订单号(日期(年月日时分秒)拼上用户id)订单号总长度规定23位,不够用随机数补位
- static function getOrdNum($uid)
- {
- //生成订单号(日期(年月日时分秒)拼上用户id)订单号总长度规定23位,不够用随机数补位
- $ord_num = date("YmdHis", time()) . $uid;
- $num = 23 - (strlen($ord_num));
- $ord_num .= rand(str_pad(1, $num, 0, STR_PAD_RIGHT), str_pad(9, $num, 9, STR_PAD_RIGHT));
- return $ord_num;
- }
- //vod开关机
- /*$ordType 订单类型 1正常 2续时 3换房 30换房后 31线下换房 32线下换房后 4退款' */
- static function vodBoot($hmUrl, $hmId, $switch = 1,$actId = '',$ordId='',$ordType=0)
- {
- if ($switch) {
- if ($actId != '') {
- if (Cache::get($actId . $ordId) != 1) {
- $actInsert = self::actInfo($actId, $ordId);
- if (!$actInsert) {
- $data['status'] = 0;
- $data['msg'] = '虚拟套餐有误';
- return $data;
- } else {
- Cache::set($actId . $ordId, 1, 3600 * 24);
- }
- }
- }
- }
- $data['status'] = 1;
- $data['msg'] = '开机成功';
- return $data;
- //获取签名
- $sData['boxid'] = $hmId;
- $sData['random'] = time();
- $sign = self::genSign($sData);
- //开机接口
- if ($switch) {
- $hmUrl .= '/StartRoom?boxid=' . $hmId . '&random=' . $sData['random'] . '&sign=' . $sign;
- } else {//关机
- $hmUrl .= '/CloseRoom?boxid=' . $hmId . '&random=' . $sData['random'] . '&sign=' . $sign;
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $hmUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- if (!empty($data)) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- $out = curl_exec($ch);
- curl_close($ch);
- //判断返回的数据是否是xml
- $re = xml_parse(xml_parser_create(), $out);
- if (!$re) {
- $data['status'] = '-1';
- $data['msg'] = '请求地址错误';
- return $data;
- }
- $xml = simplexml_load_string($out);
- $xmlJson = json_encode($xml);
- $arr = json_decode($xmlJson, true);
- if ($switch) {
- if (!empty($arr['StartRoomINFO']['STATUS'])) {
- //检查活动套餐添加详情
- if ($actId != '') {
- if (Cache::get($actId . $ordId) != 1) {
- $actInsert = self::actInfo($actId, $ordId);
- if ($actInsert) {
- Cache::set($actId . $ordId, 1, 3600 * 24);
- }
- }
- }
- $data['status'] = 1;
- $data['msg'] = '开机成功';
- } else if (!empty($arr['ERROR'])) {
- //检查活动套餐添加详情
- if ($actId != '') {
- if (Cache::get($actId . $ordId) != 1) {
- $actInsert = self::actInfo($actId, $ordId);
- if ($actInsert) {
- Cache::set($actId . $ordId, 1, 3600 * 24);
- }
- }
- }
- $data['status'] = 2;
- $data['msg'] = '已开机';
- } else {
- $data['status'] = 0;
- $data['msg'] = '开机失败,请联系工作人员';
- }
- } else {
- if (!empty($arr['CloseRoomINFO']['STATUS'])) {
- $data['status'] = 1;
- $data['msg'] = '关机成功';
- } else if (!empty($arr['ERROR'])) {
- $data['status'] = 2;
- $data['msg'] = '已关机';
- } else {
- $data['status'] = 0;
- $data['msg'] = '关机失败,请联系工作人员';
- }
- }
- return $data;
- }
- //调取签名接口
- static function genSign($url, $plus = null)
- {
- //删除签名参数
- unset($url['sign']);
- //升序排序参数
- ksort($url);
- //加盐参数
- $salt = '---happyktv';
- //拼接加密url
- $encUrl = null;
- foreach ($url as $k => $v) {
- $encUrl .= $encUrl ? '&' . $k . '=' . $v : $k . '=' . $v;
- }
- //md5签名 获取包厢类型时加盐
- if ($plus) {
- $encUrl = $salt . $encUrl;
- }
- $sign = md5($encUrl);
- return $sign;
- }
- /**
- * 获取包厢相关价格
- * @param $stoId @门店
- * @param $boxType @包厢类型
- * @param $screenings @场次
- * @param $actId @活动id
- * @param $selDate @查询日期
- * @param $source @来源
- * @return false|\PDOStatement|string|\think\Collection
- */
- static function boxPricing($stoId, $boxType, $screenings, $actId, $selDate, $source = 0)
- {
- $model = new \app\admins\model\Common();
- $where = "sto_id = {$stoId} and sto_type_id = {$boxType} and
- field_id = {$screenings} and act_id = {$actId} and use_status = 1 and del_status = 1";
- if($source == 1){
- $where.= ' and wx_show = 1';
- }
- //获取包厢相关定价
- $bp = $model->getFind('box_price', $where, 'id, up_price, down_price, act_id, minus_id');
- //获取包厢数据加价
- if ($bp) {
- $where = "box_price_id = {$bp['id']} and use_status = 1 and del_status = 1";
- if($source == 1){
- $where.= ' and wx_show = 1';
- }
- $jj = $model->getList('box_chase_price', $where, 'id, time, up_price, down_price');
- foreach ($jj as $k => $v) {
- $dates = explode(',', $v['time']);
- foreach ($dates as $k1 => $d) {
- if ($selDate == $d) {
- $bp['up_price'] = $bp['up_price'] + $v['up_price'];
- $bp['down_price'] = $bp['down_price'] + $v['down_price'];
- break;
- }
- }
- }
- }
- return $bp;
- }
- /**
- * 最新获取包厢相关价格
- * @param $stoId @门店
- * @param $boxType @包厢类型
- * @param $screenings @场次
- * @param $actId @活动id
- * @param $selDate @查询日期
- * @param $source @来源
- * @return false|\PDOStatement|string|\think\Collection
- */
- static function boxPricingNewest($stoId, $boxType, $screenings, $actId, $selDate)
- {
- $model = new \app\admins\model\Common();
- $where = "sto_id = {$stoId} and sto_type_id = {$boxType} and
- field_id = {$screenings} and act_id = {$actId} and use_status = 1 and del_status = 1";
- //获取包厢相关定价
- $bp = $model->getFind('box_price', $where, 'id, up_price, down_price, act_id, minus_id, wx_show');
- //获取包厢数据加价
- if ($bp) {
- $where = "box_price_id = {$bp['id']} and use_status = 1 and del_status = 1";
- $jj = $model->getList('box_chase_price', $where, 'id, time, up_price, down_price, wx_show');
- foreach ($jj as $k => $v) {
- $dates = explode(',', $v['time']);
- foreach ($dates as $k1 => $d) {
- if ($selDate == $d) {
- $bp['up_price'] = $bp['up_price'] + $v['up_price'];
- $bp['down_price'] = $bp['down_price'] + $v['down_price'];
- $bp['wx_show'] = $v['wx_show'];
- break;
- }
- }
- }
- }
- return $bp;
- }
- //获取包场不同类型房间价格
- static function boxTypePrice($stoId, $boxType, $screenings)
- {
- $model = new \app\admins\model\Common();
- return $model->getFind('set_bao_reserve_price', "shop_id = {$stoId} and box_type = {$boxType} and genre = {$screenings}",
- 'id, price, un_line_price');
- }
- //查询订单退款比例规则
- /*
- * $stoId 门店id
- * */
- static function ref_role($stoId, $type)
- {
- // $where['shop_id'] = $stoId;
- $where['genre'] = $type;
- $table = 'set_refund_ratio';
- $filed = 'start,finish,ratio';
- $model = new \app\admins\model\Common();
- $re = $model->getList($table, $where, $filed);
- $ratio = 100;
- //获取当前时间的年月日
- $date = date('Y-m-d');
- //获取当前时间戳
- $time = time();
- $aEndTime = array();
- //将查询出的时间进行拼接日期比较获取响应的扣款比例
- foreach ($re as $k => $v) {
- $startTime = strtotime($date . ' ' . $v['start']);
- $endTime = strtotime($date . ' ' . $v['finish']);
- if ($endTime < $startTime) {
- $endTime = $endTime + (24 * 60 * 60);
- }
- $aEndTime['endTime'][] = $endTime;
- }
- $maxEndTime = strtotime($date . ' ' . date('H:i:s', max($aEndTime['endTime'])));
- $maxYEndTime = date('Y-m-d', max($aEndTime['endTime']));
- if ($time < $maxEndTime && $maxYEndTime > $date) {
- $date = date('Y-m-d', strtotime($date) - (24 * 60 * 60));
- }
- foreach ($re as $k => $v) {
- $startTime = strtotime($date . ' ' . $v['start']);
- $endTime = strtotime($date . ' ' . $v['finish']);
- if ($endTime < $startTime) {
- $endTime = $endTime + (24 * 60 * 60);
- }
- //判断当前时间是否在查询出来的时间段内
- if ($time < $startTime) {
- $ratio = 0;
- } else if ($startTime <= $time && $time <= $endTime + 59) {
- $ratio = $v['ratio'];
- echo $ratio;
- break;
- } else if ($time > $endTime) {
- $ratio = 100;
- }
- }
- return $ratio;
- //将查询出的时间进行拼接日期比较获取响应的扣款比例
- }
- //获取指定门店场次
- static function stoScreenings($stoId)
- {
- if (empty($stoId)) {
- return null;
- }
- $model = new StoreBoxModel();
- return $model->getList('set_bao_reserve', "shop_id = {$stoId} and status = 1 and del_status = 1",
- 'id ,genre, start, finish, alias', 'genre asc');
- }
- //套餐详情查询失败返回false
- static function goodsInfo($id, $filed = '*')
- {
- $model = new StoreBoxModel();
- $where['id'] = $id;
- $re = $model->getFind('act_content', $where, 'include,cost_price,up_price,down_price');
- if (empty($re)) {
- return false;
- }
- //切割字符串成数组
- $array = array();
- $arr = explode('&', $re['include']);
- foreach ($arr as $k => $v) {
- $_arr = explode(';', $v);
- foreach ($_arr as $kk => $vv) {
- $a = explode("=", $vv);
- $array[$k][$a[0]] = $a[1];
- }
- }
- $goodsInfo = array();
- $goodsInfo['act_cost_price'] = $re['cost_price'];
- $goodsInfo['act_up_price'] = $re['up_price'];
- $goodsInfo['act_down_price'] = $re['down_price'];
- foreach ($array as $k => $v) {
- //查询商品信息
- $where['id'] = $v['gid'];
- $res = $model->getFind('product', $where, $filed);
- $goodsInfo['info'][$k] = $res;
- //查询商品类型
- $where['id'] = $v['tid'];
- $type = $model->getFind('product_category', $where, 'shop_name');
- $goodsInfo['info'][$k]['type_name'] = $type['shop_name'];
- $goodsInfo['info'][$k]['act_num'] = $v['num'];
- }
- return $goodsInfo;
- }
- //获取门店场次时间
- static function stoTimePeriod($stoId, $genre)
- {
- if (empty($stoId)) {
- return null;
- }
- $model = new StoreBoxModel();
- return $model->getFind('set_bao_reserve', "shop_id = {$stoId} and genre = {$genre} and status = 1 and del_status = 1",
- 'id , start, finish');
- }
- /**
- * 获取活动套餐产品id,数量
- * @param $proSource @产品源信息
- * @return array
- */
- static function actProInfo($proSource)
- {
- //活动产品
- $actPros = null;
- if (empty($proSource)) {
- return $actPros;
- }
- $yPro = explode('&', $proSource);
- $yyCp = [];
- $a1 = [];
- foreach ($yPro as $k => $v) {
- $yPros = explode(';', $v);
- $a1[] = $yPros[0];
- $a1[] = $yPros[2];
- $yyCp[] = $a1;
- $a1 = null;
- }
- foreach ($yyCp as $v1) {
- $aa = explode('=', $v1[0]);
- $bb = explode('=', $v1[1]);
- $yp['id'] = $aa[1];
- $yp['num'] = $bb[1];
- $actPros[] = $yp;
- $yp = null;
- }
- return $actPros;
- }
- /**
- * 获取应补套餐
- * @param $yyCp @小包厢套餐
- * @param $xxCp @大包厢套餐
- * @return array|int|null
- */
- static function supplyMeal($yyCp, $xxCp)
- {
- //检查套餐设置是否正确
- $tag = 0;
- //应补产品
- $nPro = null;
- //检查产品数量
- $a = 0;
- if(!empty($yyCp)){
- foreach($yyCp as $v){
- $a = $a + $v['num'];
- }
- }
- //检查产品数量
- $b = 0;
- if(!empty($xxCp)){
- foreach($xxCp as $v){
- $b = $b + $v['num'];
- }
- }
- //大换小
- if($a > $b){
- $temp = $yyCp;
- $yyCp = $xxCp;
- $xxCp = $temp;
- }
- if (!empty($yyCp) && !empty($xxCp)) {
- foreach ($yyCp as $v) {
- $have = 0;
- foreach ($xxCp as $v1) {
- if ($v['id'] == $v1['id']) {
- $have = 1;
- }
- }
- if (!$have) {
- $tag = 1;
- break;
- }
- }
- }
- //小换大,获取应补产品
- if ($a < $b && !$tag) {
- foreach ($xxCp as $v1) {
- $data['id'] = $v1['id'];
- $data['num'] = $v1['num'];
- if (!empty($yyCp)) {
- foreach ($yyCp as $v) {
- if ($v1['id'] == $v['id']) {
- $data['num'] = $v1['num'] - $v['num'];
- if ($data['num'] < 0) {
- $tag = 1;
- }
- }
- }
- }
- if($data['num'] > 0){
- $nPro[] = $data;
- }
- $data = null;
- }
- }
- if ($tag) {
- return -1;
- }
- return $nPro;
- }
- /**
- * 获取商品活动套餐商品明细
- * @param $ordId @订单id
- * @param $actType @活动类型 1普通商品 2活动套餐 3商品套餐 4增值服务 5换酒
- * @return false|\PDOStatement|string|\think\Collection
- */
- static function ordActPros($ordId, $actType){
- $model = new ProductModel();
- return $model->getList('user_order_goods', "ord_id = {$ordId} and goods_source = {$actType}", 'goods_id as id, goods_num as num');
- }
- //库存信息的改变
- static function achieve($proId, $count, $genre, $desc)
- {
- $list = Common::fulfill($proId, $count, $genre);
- if ($list) {
- $data = Common::information($proId);
- Common::proOut($data, $count, $genre, $desc);
- //$returnData['status'] = '库存改变成功';
- $returnData = 1;
- } else {
- //$returnData['msg'] = '库存改变失败';
- $returnData = 0;
- }
- return $returnData;
- }
- /**
- * 订单完成改变库存
- * @param array $pros @产品id
- * @param $storage @仓库id
- * @param array $ckType @出口类型 格式['add' => 1,0减库存 1加库存 'type' => 'ys' zs为真实库存 ys为预售库存]
- * @return int
- */
- static function stockHandle($pros, $storage, $ckType)
- {
- $model = new ProductModel();
- //预售出库
- if($ckType['type'] == 'ys'){
- $field = 'advance_num';
- }else{//真实出库
- $field = 'stock';
- }
- $result = 0;
- foreach($pros as $v){
- $where = "product_id = {$v['id']} and storage_id = {$storage}";
- if($ckType['add'] == 1){
- $result = $model->table('ktv_product_storage')->where($where) ->setInc($field, $v['num']);
- } else{
- $result = $model->table('ktv_product_storage')->where($where) ->setDec($field, $v['num']);
- }
- }
- return $result;
- }
- //查询商品的信息
- static function information($pro_id)
- {
- $model = new ProductModel();
- $where = "id = $pro_id";
- $filed = 'id,shop_id,pro_coding,nameer,pro_specification,unit,number,pro_category';
- return $model->getFind('product', $where, $filed);
- }
- //出库记录
- static function proOut($data, $count, $genre, $desc)
- {
- $model = new ProductModel();
- if ($genre == 1) {
- $gen = '-' . $count;
- } else {
- $gen = '+' . $count;
- }
- $arr = [
- 'ent_id' => $data['id'],
- 'shop_id' => $data['shop_id'],
- 'genre' => $genre,
- 'pro_coding' => $data['pro_coding'],
- 'name' => $data['nameer'],
- 'pro_specification' => $data['pro_specification'],
- 'unit' => $data['unit'],
- 'num' => $gen,
- 'pro_category' => $data['pro_category'],
- 'particulars' => $desc,
- 'add_time' => date('Y-m-d H:i:s'),
- 'adm_id' => Cookie::get('admin_id')
- ];
- $bank = $model->addData('warehouse', $arr);
- //日志
- if ($bank) {
- $CAdmBase = new \app\base\CAdmBase;
- $centent = $genre == 1 ? '添加出库信息 id:' . $bank : '添加入库信息 id:' . $bank;
- $CAdmBase->addOperation("warehouse", 1, $centent);
- // if ($genre == 1) {
- // Common::logs('添加出库信息 id:' . $bank);
- // } else {
- // Common::logs('添加入库信息 id:' . $bank);
- // }
- }
- return $bank;
- }
- //==================================投票代码================================================
- //赠送次数添加
- static function addNum($uid, $winOrdNum)
- {
- $model = new ProductModel();
- //查询表中是否有uid
- $table = 'vote_num';
- //查询酒水定单的付款金额
- if (!empty($winOrdNum)) {
- $where['ord_num'] = $winOrdNum;
- $filed = 'amount';
- $amount = $model->getFind('user_drinks_order', $where, $filed);
- unset($where);
- $where['uid'] = $uid;
- $num = ceil($amount['amount']);
- $re = $model->getFind($table, $where, 'id');
- if ($re) {
- //有信息直接修改次数
- $re = Db::table('ktv_' . $table)->where($where)->setInc('extra_num', $num);
- } else {
- //没有信息查询用户表在添加到表中
- unset($where);
- $where['id'] = $uid;
- $openid = $model->getFind('user', $where, 'openid');
- if (!empty($openid)) {
- $data['uid'] = $uid;
- $data['openid'] = $openid['openid'];
- $data['extra_num'] = $num;
- $model->addData($table, $data);
- }
- }
- }
- }
- //==================================投票代码================================================
- //生成采购库存订单号
- static function pwOrdNum($prefix)
- {
- return $prefix . date('Ymds') . rand(1000, 9999);
- }
- //获取用户openId
- static function getOpenIdByUid($uid)
- {
- $model = new ModelUserAdmin();
- return $model->getFind('user', "id = {$uid}", 'openid');
- }
- /**
- * 验证输入的邮件地址是否合法
- *
- * @param string $email 需要验证的邮件地址
- *
- * @return bool
- */
- function if_email($email)
- {
- $chars = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
- if (strpos($email, '@') !== false && strpos($email, '.') !== false) {
- if (preg_match($chars, $email)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- /**
- * 验证输入的手机号是否正确
- * @return boolean
- */
- function if_mobile($mobile)
- {
- if (preg_match('/^1(3|4|5|6|7|8|9)[0-9]{9}$/', $mobile)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 验证输入的电话是否正确
- * @return boolean
- */
- function if_tel($tel)
- {
- if (preg_match('/^([0-9]{3,4}-)?[0-9]{7,8}$/', $tel)) {
- return true;
- } else {
- return false;
- }
- }
- /*
- * 仓库列表 (录入与采购退货)
- * $keyword 商品编号或者商品拼音
- * $storage_id 仓库ID
- * */
- static function storage_product_list($keyword, $storage_id = 0)
- {
- $logic = new \app\admins\logic\Purchase;
- $store_id = cookie('admin_control_store');
- $where = "b.id != 0 and a.shop_id = '{$store_id}' and a.status = 1 and (a.pro_coding='{$keyword}' or a.spell like '%{$keyword}%')";
- $field = "a.id,a.pro_coding,a.nameer,a.unit,a.pro_specification,a.cost,a.spell";
- $product_list = $logic->JoinModel("product", "product_category", $where, "a.pro_category=b.id", $field);
- foreach ($product_list as $key => $val) {
- $info = $logic->getInfoModel("product_storage", "product_id = '{$val['id']}' and storage_id = '{$storage_id}'");
- $product_list[$key]['number'] = isset($info) ? $info['stock'] : 0;
- }
- if ($product_list) {
- return $product_list;
- } else {
- return false;
- }
- }
- /*
- * 仓库列表 (库存调拨,报损报溢)
- * $keyword 商品编号或者商品拼音
- * $storage_id 仓库ID
- * */
- static function new_storage_product_list($keyword, $storage_id)
- {
- $logic = new \app\admins\logic\Purchase;
- $store_id = cookie('admin_control_store');
- $where = "c.storage_id = '{$storage_id}' and b.id != 0 and a.shop_id = '{$store_id}' and a.status = 1 and (a.pro_coding='{$keyword}' or a.spell like '%{$keyword}%')";
- $field = "a.id,a.pro_coding,a.nameer,a.unit,a.pro_specification,a.cost,a.spell,c.stock as number";
- $product_list = Db::name("product")
- ->alias("a")
- ->join("product_category b", "a.pro_category=b.id")
- ->join("product_storage c", "a.id=c.product_id")
- ->field($field)
- ->where($where)
- ->select();
- if ($product_list) {
- return $product_list;
- } else {
- return false;
- }
- }
- /**
- * 添加信息至库存表及库存商品详情
- * @param $restocking @string|int 库存类型
- * @param $storage_id @string|int 仓库ID
- * @param $product_list @array商品信息 (sales_type销售类型(restocking等于8的时候传)real_total_price实际总金额,reference_total_price参考总金额,real_price实际价格,reference_price销售价格 product_id商品ID,amount数量(寄存数量或退单数量),remark备注(商品备注可有可没有))
- * @param $remark @string 入库备注信息备注信
- * @param $uid
- * @param $payable @string 实付价格
- * @param $payment @string 应付价格
- * @param $thing @string false就是使用事物,true就是不使用事物
- * @return bool
- */
- static function storage_operate_add($restocking, $storage_id, $product_list, $uid = 0, $remark = 0, $payable = 0, $payment = 0,$thing=false)
- {
- if (!empty($product_list)) {
- $model = new \app\admins\model\Purchase;
- $logic = new \app\admins\logic\Purchase;
- $ord_num = self::pwOrdNum($model->put_type[$restocking]); //生成一个订单号
- $time = date("Y-m-d H:i:s");
- $data = array(
- "ord_num" => $ord_num,
- "restocking" => $restocking,
- "add_time" => $time,
- "storage_id" => $storage_id,
- "adm_id" => $uid ? $uid : cookie("admin_id"),
- "remark" => $remark,
- "payable" => $payable,
- "payment" => $payment,
- );
- return $logic->AddProductPut($data, $product_list, $uid,$thing);
- }
- return false;
- }
-
- //打单处理预售库存与真实库存
- /*
- * prodcut_list = array(
- * storage_id => int 仓库ID
- * gid => int 商品ID
- * num => int 商品数量
- * )
- * type 0减
- */
- static function ProductStorageEdit($product_list = array(),$type=0){
- if(empty($product_list) || $type>0){
- return false;
- }
- $logic = new \app\admins\logic\Purchase;
- foreach($product_list as $key=>$val){
- $where = "storage_id = '{$val['storage_id']}' and product_id = '{$val['gid']}'";
- $info = $logic->getInfoModel("product_storage", $where);
- if(isset($info)){
- if($type == 0){
- $data = array(
- 'stock' => intval($info['stock']) - intval($val['num']),
- 'advance_num'=> intval($info['advance_num']) - intval($val['num']),
- );
- }
- $result = $logic->UpdateModel("product_storage", $where, $data);
- }
- }
- return true;
-
- }
- //获取门店销售仓库
- static function getSaleStorage($stoId)
- {
- $store = new StoreBoxModel();
- $result = $store->getFind('store', "id = {$stoId}", 'storage_id');
- if (!empty($result['storage_id'])) {
- return $result['storage_id'];
- }
- return null;
- }
- //报表中心导航栏
- static function navigation()
- {
- $param = array(
- "put_storage" => array(
- "name" => "入库管理报表",
- "list" => array(
- 0 => array("url" => "/admins/report/put_product", "name" => "商品入库明细表"),
- 1 => array("url" => "/admins/report/put_product_gather", "name" => "商品入库汇总表"),
- 2 => array("url" => "/admins/report/put_storage", "name" => "仓库收货明细表"),
- 3 => array("url" => "/admins/report/put_storage_gather", "name" => "仓库收货汇总汇表"),
- 4 => array("url" => "/admins/report/put_supplier?restocking=1", "name" => "供应商供货明细表"),
- 5 => array("url" => "/admins/report/put_supplier_gather?restocking=1", "name" => "供应商供货汇总表"),
- ),
- ),
- "out_storage" => array(
- "name" => "出库管理报表",
- "list" => array(
- 0 => array("url" => "/admins/report/put_product?do=1", "name" => "商品出库明细表"),
- 1 => array("url" => "/admins/report/put_product_gather?do=1", "name" => "商品出库汇总表"),
- 2 => array("url" => "/admins/report/put_supplier?restocking=2", "name" => "供应商退货明细表"),
- 3 => array("url" => "/admins/report/put_supplier_gather?restocking=2", "name" => "供应商退货汇总表"),
- ),
- ),
- "storage" => array(
- "name" => "库存管理报表",
- "list" => array(
- 0 => array("url" => "/admins/report/allocate_transfer", "name" => "调拨明细表"),
- 1 => array("url" => "/admins/report/allocate_transfer_gather", "name" => "调拨汇总表"),
- 2 => array("url" => "/admins/report/product_check?restocking=6", "name" => "报损明细表"),
- 3 => array("url" => "/admins/report/product_check_gather?restocking=6", "name" => "报损汇总表"),
- 4 => array("url" => "/admins/report/product_check?restocking=7", "name" => "报溢明细表"),
- 5 => array("url" => "/admins/report/product_check_gather?restocking=7", "name" => "报溢汇总表"),
- 6 => array("url" => "/admins/report/product_list", "name" => "商品库存表"),
- ),
- ),
- "finance" => array(
- "name" => "财务报表",
- "list" => array(
- 0 => array("url" => "/admins/finance/business", "name" => "营业账单查询"),
- // 1 => array("url" => "/admins/finance/box", "name" => "包厢消费明细表"),
- 1 => array("url" => "/admins/Reportcontroller/boxDetailList", "name" => "包厢消费明细表"),
- 2 => array("url" => "/admins/finance/kitchen", "name" => "厨房出品明细表"),
- // 3 => array("url" => "/admins/finance/bar_counter", "name" => "吧台营业日报表"),
- 3 => array("url" => "/admins/Reportcontroller/dayReport", "name" => "吧台营业日报表"),
- 4 => array("url" => "/admins/finance/sell", "name" => "商品销售明细表"),
- 5 => array("url" => "/admins/finance/give", "name" => "赠送明细表"),
- 6 => array("url" => "/admins/finance/deposit", "name" => "商品寄存明细表"),
- // 7 => array("url" => "/admins/finance/goodsSum", "name" => "销售汇总"),
- 7 => array("url" => "/admins/Reportcontroller/sellSum", "name" => "销售汇总"),
- 8 => array("url" => "/admins/finance/refaultPriceList", "name" => "退款报表"),
- 9 => array("url" => "/admins/finance/winOrd", "name" => "酒水订单报表"),
- 10 => array("url" => "/admins/Reportcontroller/cardFirst", "name" => "会员首充门店表"),
- ),
- )
- );
- return $param;
- }
- /**
- * 库存数量检查
- * @param $actPros @活动套餐,商品套餐
- * 格式
- * $actPros = [
- ['act_id' => 1, 'amount' => 2, 'storage_id' => 3],
- ['act_id' => 3, 'amount' => 1, 'storage_id' => 3],
- ];
- * @param $comPros @商品信息
- * 格式
- $comPros = [
- ['pro_id' => 3, 'amount' => 10, 'storage_id' => 3],
- ['pro_id' => 4, 'amount' => 1, 'storage_id' => 3],
- ];
- *
- * @return mixed
- */
- static function inventoryCheck($actPros, $comPros)
- {
- //购买产品
- $pros = [];
- $storage = 0; //仓库id
- if (!empty($actPros)) {
- $storage = $actPros[0]['storage_id'];
- if (empty($storage)) {
- echo '套餐未指定仓库id';
- die;
- }
- //获取活动信息
- $model = new ProductModel();
- $ids = join(',', array_column($actPros, "act_id"));
- $list = $model->getList('act_content', "id in ($ids) and act_type_id != 3 and act_type_id != 4", 'id,act_name, include');
- foreach ($list as $k1 => $v1) {
- foreach ($actPros as $k2 => $v2) {
- $v1['id'] == $v2['act_id'] ? $list[$k1]['amount'] = $v2['amount'] : "";
- }
- }
- foreach ($list as $v) {
- //获取活动包含商品
- $actTc = explode('&', $v['include']);
- if (!empty($actTc)) {
- foreach ($actTc as $v1) {
- $pro = explode(';', $v1);
- if (!empty($pro)) {
- $proStr = explode('=', $pro[0]);
- $amountStr = explode('=', $pro[2]);
- if (!empty($proStr)) {
- //购买数据 = 套餐内数量 * 购买套餐数量
- $buyAmount = $amountStr[1] * $v['amount'];
- $t['pro_id'] = $proStr[1];
- $t['pro_amount'] = $buyAmount;
- $t['storage_id'] = $storage;
- //添加产品
- if (empty($pros)) {
- $pros[] = $t;
- } else {
- $isAdd = 0;
- foreach ($pros as $k => $p) {
- //修改产品数量
- if ($p['pro_id'] == $t['pro_id']) {
- $pros[$k]['pro_amount'] = $p['pro_amount'] + $t['pro_amount'];
- $isAdd = 1;
- }
- }
- //添加产品
- if (!$isAdd) {
- $pros[] = $t;
- }
- }
- }
- }
- }
- }
- }
- }
- //合并产品中产品数量
- if (!empty($comPros)) {
- foreach ($comPros as $v) {
- $t['pro_id'] = $v['pro_id'];
- $t['pro_amount'] = $v['amount'];
- $t['storage_id'] = $v['storage_id'];
- //添加产品
- if (empty($pros)) {
- $pros[] = $t;
- } else {
- $isAdd = 0;
- foreach ($pros as $k => $p) {
- //修改产品数量
- if ($p['pro_id'] == $t['pro_id']) {
- $pros[$k]['pro_amount'] = $p['pro_amount'] + $t['pro_amount'];
- $isAdd = 1;
- }
- }
- //添加产品
- if (!$isAdd) {
- $pros[] = $t;
- }
- }
- }
- }
- $data['status'] = 0;
- $data['msg'] = null;
- //检查产品库存
- if (!empty($pros)) {
- $model = new ProductModel();
- foreach ($pros as $v) {
- //获取商品信息
- // $pro = $model->getFind('product', "id ={$v['pro_id']}", 'nameer, number');
- $pro = $model->joinTableData('product_storage',
- 'product',
- "a.storage_id = {$v['storage_id']} and product_id = {$v['pro_id']}",
- 'a.product_id = b.id',
- 'b.nameer, a.stock, a.advance_num'
- );
- if (!empty($pro)) {
- $AvaStock = $pro['stock'] - $pro['advance_num'];
- if ($v['pro_amount'] > $AvaStock) {
- $data['status'] = 1;
- $data['msg'] .= '商品‘' . $pro['nameer'] . '’库存不足,仅可售' . $AvaStock . '份。';
- break;
- }
- } else {
- $data['status'] = 1;
- $data['msg'] .= '商品id:' . $v['pro_id'] . '可能删除或更改';
- break;
- }
- }
- }
- return $data;
- }
- /**
- * 获取门店场次
- * @param $req
- * @param $source 0前端 1后端
- * @return false|\PDOStatement|string|\think\Collection
- */
- static function stoField($req, $source = 0)
- {
- $model = new StoreBoxModel();
- //获取当前门店的场次
- $where['shop_id'] = $req['sto_id'];
- $where['status'] = 1;
- $where['del_status'] = 1;
- $filed = 'id, alias, genre, start, finish';
- $list = $model->getList('set_bao_reserve', $where, $filed, 'genre asc');
- $selDate = $req['date_select'];
- $now = date('Y-m-d H:i:s');
- //更改场次时段是否可选
- foreach ($list as $k => $v) {
- $sdStart = $selDate . ' ' . $v['start'];
- $sdEnd = $selDate . ' ' . $v['finish'];
- if ($sdEnd < $sdStart) {
- $sdEnd = date('Y-m-d H:i:s', strtotime($sdEnd) + 86400);;
- }
- if($now >= $req['old_start_time'] && $now <= $req['old_end_time']){//开机内换房
- //来自后端,未开机
- if($source && $req['ord_status'] == 1){
- $list[$k]['status'] = 1;
- }else{
- if($now >= $sdStart and $now <= $sdEnd){
- $list[$k]['status'] = 1;
- }else{
- $list[$k]['status'] = 0;
- }
- }
- }else if($now < $sdStart && $now < $req['old_start_time']){//未到欢唱时间换房
- $list[$k]['status'] = 1;
- }else{
- if($source){//来源后端
- $list[$k]['status'] = 1;
- }else{
- $list[$k]['status'] = 0;
- }
- }
- }
- return $list;
- }
- //获取满减达到金额
- static function fullCutMoney($minusId)
- {
- $model = new StoreBoxModel();
- //获取满减规则
- $act = $model->getFind('act_content', "id = {$minusId}", 'include');
- if (!empty($act['include'])) {
- $actCont = explode('|', $act['include']);
- return is_array($actCont) ? $actCont[0] : 0;
- }
- return null;
- }
- /**
- * 获取换房价格
- * @param $req
- * @param null $order
- * @param null $ordSource
- * @param int $bActType @要更换套餐类型 1为虚拟套餐
- * @return string
- */
- static function getExchangePrice($req, $order = null, $ordSource = null, $bActType = 0)
- {
- //这一步通常是前端换包调取应补差价
- if (empty($order)) {
- $now = date('Y-m-d H:i:s');
- //获取原来订单信息
- $model = new StoreBoxModel();
- if (!empty($req['old_ord_id'])) {
- $where = "id = '{$req['old_ord_id']}' and ord_status in ('1', '2') and end_time > '{$now}'";
- } else {
- $where = "ord_num = '{$req['old_ord_num']}' and ord_status in ('1', '2') and end_time > '{$now}'";
- }
- $order = $model->getFind('user_order', $where, 'ord_status, hours, start_time, end_time, act_id,
- box_price, amount, full_cut, full_cut_amount'
- );
- }
- if (empty($order)) {
- $data['status'] = 0;
- $data['msg'] = '已超时';
- return json_encode($data);
- }
- //获取换房包厢或套餐价格
- $chgOrder = Common::boxPricing($req['sto_id'], $req['new_box_type'], $req['sel_time_way'], $req['sel_act_id'], $req['new_sel_date']);
- if (empty($chgOrder['up_price'])) {
- $data['status'] = 0;
- $data['msg'] = '未定义包厢价格';
- return json_encode($data);
- }
- //添加开机后,套餐包不能换虚拟套餐
- //if($order['act_id'] && $order['ord_status'] == 2 && $bActType){
- // $data['status'] = 0;
- // $data['msg'] = '开机后,套餐包不能换虚拟套餐包';
- // return json_encode($data);
- //}
- $boxPrice = $order['box_price'];
- $amount = $order['amount'];
- $chgPrice = $ordSource == 3 ? $chgOrder['down_price'] : $chgOrder['up_price'];
- $data['type'] = null;
- //裸包换裸包
- $lToL = empty($order['act_id']) && empty($req['sel_act_id']);
- //套餐换套餐
- $tToT = !empty($order['act_id']) && $req['sel_act_id'];
- //裸包换套餐
- $lToT = empty($order['act_id']) && $req['sel_act_id'];
- //套餐换裸包
- $tToL = !empty($order['act_id']) && empty($req['sel_act_id']);
- //开机前
- if ($order['ord_status'] == 1) {
- if ($tToL) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '套餐包不能换裸包';
- return json_encode($data);
- } else if ($lToT && !empty($order['full_cut']) && !empty($order['full_cut_amount'])) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '已使用满减的裸包不能换套餐包';
- return json_encode($data);
- }else if ($lToL && !empty($order['full_cut_amount']) && empty($req['new_minus_id'])) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '已使用满减的包不能更换无满减的包';
- return json_encode($data);
- } else {
- $data['status'] = 1;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '';
- //1. 裸包换裸包、无使用满减、小包a换小包b
- if ($lToL && empty($order['full_cut']) && $boxPrice == $chgPrice) {
- } else if ($lToL && empty($order['full_cut']) && $boxPrice < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- } else if ($lToL && empty($order['full_cut']) && $boxPrice > $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //2. 裸包换裸包、有满减、已使用,小包a换小包b
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice == $chgPrice) {
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice < $chgPrice) {
- //获取现在要达到的满减
- // $nowFullMoney = Common::fullCutMoney($order['full_cut']);
- //获取已买酒水金额
- $usrWinMoney = Db::name('user_drinks_order')->where("box_id = {$req['box_id']} and start_time <= '{$req['new_start_time']}' and
- end_time >= '{$req['new_start_time']}' and time_way = {$req['sel_time_way']} and
- pay_state in (1, 2, 3)")->sum('amount');
- //获取新包满减
- $fullMoney = Common::fullCutMoney($req['new_minus_id']);
- $difMoney = $fullMoney - $usrWinMoney;
- if ($difMoney > 0) {
- $difMoney = self::ktvMoney($difMoney);
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '您再购买酒水' . $difMoney . '元,才能达到满减条件';
- return json_encode($data);
- }else{
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice > $chgPrice) {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- //3. 裸包换裸包、有满减、未使用,小包a换小包b
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- //4. 套餐换套餐、小包套餐a换小包套餐b
- } else if ($tToT && empty($order['full_cut']) && $amount == $chgPrice) {
- //开机前,套餐换套餐,小换小
- $data['type'] = 'qtt_xx';
- } else if ($tToT && empty($order['full_cut']) && $amount < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,套餐换套餐,小换大
- $data['type'] = 'qtt_xd';
- } else if ($tToT && empty($order['full_cut']) && $amount > $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,套餐换套餐,大换小
- $data['type'] = 'qtt_dx';
- //5. 无满减裸包换套餐包
- } else if ($lToT && empty($order['full_cut']) && $boxPrice == $chgPrice) {
- //开机前,裸包换套餐,小换小
- $data['type'] = 'qlt_xx';
- } else if ($lToT && empty($order['full_cut']) && $boxPrice < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,裸包换套餐,小换大
- $data['type'] = 'qlt_xd';
- } else if ($lToT && empty($order['full_cut']) && $boxPrice > $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,裸包换套餐,大换小
- $data['type'] = 'qlt_dx';
- //6. 有满减,未使用裸包换套餐包
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,裸包换套餐,有满减,未使用,小换小
- $data['type'] = 'qlt_yw_xx';
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,裸包换套餐,有满减,未使用,小换大
- $data['type'] = 'qlt_yw_xd';
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机前,裸包换套餐,有满减,未使用,大换小
- $data['type'] = 'qlt_yw_dx';
- }
- return json_encode($data);
- }
- } else if ($order['ord_status'] == 2) {//开机后
- if ($tToL) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '套餐包不能换裸包';
- return json_encode($data);
- } else if ($lToT && !empty($order['full_cut']) && !empty($order['full_cut_amount'])) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '已使用满减的裸包不能更换套餐包';
- return json_encode($data);
- } else if ($lToL && !empty($order['full_cut_amount']) && empty($req['new_minus_id'])) {
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '已使用满减的包不能更换无满减的包';
- return json_encode($data);
- } else {
- $data['status'] = 1;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '';
- //1. 裸包换裸包、无满减、小包a换小包b
- if ($lToL && empty($order['full_cut']) && $boxPrice == $chgPrice) {
- } else if ($lToL && empty($order['full_cut']) && $boxPrice < $chgPrice) {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- } else if ($lToL && empty($order['full_cut']) && $boxPrice > $chgPrice) {
- $data['diff_price'] = 0;
- $data['msg'] = '开机后,大包换小包不退差价';
- //2. 裸包换裸包、有满减、已使用、小包a换小包b
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice == $chgPrice) {
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice < $chgPrice) {
- //获取现在要达到的满减
- // $nowFullMoney = Common::fullCutMoney($order['full_cut']);
- //获取已买酒水金额
- $usrWinMoney = Db::name('user_drinks_order')->where("box_id = {$req['box_id']} and start_time <= '{$req['new_start_time']}' and
- end_time >= '{$req['new_start_time']}' and time_way = {$req['sel_time_way']} and
- pay_state in (1, 2, 3)")->sum('amount');
- //获取新包满减
- $fullMoney = Common::fullCutMoney($req['new_minus_id']);
- $difMoney = $fullMoney - $usrWinMoney;
- if ($difMoney > 0) {
- $difMoney = self::ktvMoney($difMoney);
- $data['status'] = 0;
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '您再购买酒水' . $difMoney . '元,才能达到满减条件';
- return json_encode($data);
- }else{
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
- && $boxPrice > $chgPrice) {
- $data['msg'] = '开机后,使用满减的大包更换满减的小包,不退差价哦';
- return json_encode($data);
- //3. 裸包换裸包、有满减、未使用、小包a换小包b
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
- $data['msg'] = '开机后,有满减的大包更换有满减的小包,不退差价哦';
- //4. 套餐换套餐、小包套餐a换小包套餐b
- } else if ($tToT && $amount == $chgPrice) {
- //开机后,套餐换套餐,小换小
- $data['type'] = 'htt_xx';
- } else if ($tToT && $amount < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机后,套餐换套餐,小换大
- $data['type'] = 'htt_xd';
- } else if ($tToT && $amount > $chgPrice) {
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '您订的套餐包不退差价哦,是否确认更换?';
- //开机后,套餐换套餐,大换小
- $data['type'] = 'htt_dx';
- //5. 无满减裸包换套餐包
- } else if ($lToT && empty($order['full_cut']) && $boxPrice == $chgPrice) {
- //开机后,裸包换套餐,无满减,未使用,小换小
- $data['type'] = 'hlt_ww_xx';
- } else if ($lToT && empty($order['full_cut']) && $boxPrice < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机后,裸包换套餐,无满减,未使用,小换大
- $data['type'] = 'hlt_ww_xd';
- } else if ($lToT && empty($order['full_cut']) && $boxPrice > $chgPrice) {
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '您订的套餐包不退差价哦,是否确认更换?';
- //开机后,裸包换套餐,无满减,未使用,大换小
- $data['type'] = 'hlt_ww_dx';
- //6. 未使用裸包换套餐包
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
- //开机后,裸包换套餐,有满减,未使用,小换小
- $data['type'] = 'hlt_yw_xx';
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
- if (!empty($order['jiuzhe'])) {
- $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
- } else {
- $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
- }
- //开机后,裸包换套餐,有满减,未使用,小换大
- $data['type'] = 'hlt_yw_xd';
- } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
- $data['diff_price'] = self::ktvMoney(0);
- $data['msg'] = '您购买的裸包含有满减活动,换包不退差价,是否更换?';
- //开机后,裸包换套餐,有满减,未使用,大换小
- $data['type'] = 'hlt_yw_dx';
- }
- return json_encode($data);
- }
- }
- //默认,无差价换包
- $data['status'] = 1;
- $data['diff_price'] = self::ktvMoney(0);
- return json_encode($data);
- }
- //去掉千位分隔符
- static function ktvMoney($price)
- {
- return number_format($price, 2, '.', '');
- }
- //获取订单付款方式
- static function ktvPayWays($ord){
- $payWay = [];
- if(!empty($ord['huiyuanka']) && $ord['huiyuanka'] != '0.00'){
- $payWay['huiyuanka'] = $ord['huiyuanka'];
- }
- if(!empty($ord['weixin']) && $ord['weixin'] != '0.00'){
- $payWay['weixin'] = $ord['weixin'];
- }
- if(!empty($ord['zhifubao']) && $ord['zhifubao'] != '0.00'){
- $payWay['zhifubao'] = $ord['zhifubao'];
- }
- if(!empty($ord['xianjin']) && $ord['xianjin'] != '0.00'){
- $payWay['xianjin'] = $ord['xianjin'];
- }
- if(!empty($ord['yinlianka']) && $ord['yinlianka'] != '0.00'){
- $payWay['yinlianka'] = $ord['yinlianka'];
- }
- if(!empty($ord['meituan']) && $ord['meituan'] != '0.00'){
- $payWay['meituan'] = $ord['meituan'];
- }
- if(!empty($ord['jifenduihuan']) && $ord['jifenduihuan'] != '0.00'){
- $payWay['jifenduihuan'] = $ord['jifenduihuan'];
- }
- if(!empty($ord['diyongjuan']) && $ord['diyongjuan'] != '0.00'){
- $payWay['diyongjuan'] = $ord['diyongjuan'];
- }
- if(!empty($ord['moling']) && $ord['moling'] != '0.00'){
- $payWay['moling'] = $ord['moling'];
- }
- if(!empty($ord['bazhe']) && $ord['bazhe'] != '0.00'){
- $payWay['bazhe'] = $ord['bazhe'];
- }
- if(!empty($ord['youhui']) && $ord['youhui'] != '0.00'){
- $payWay['youhui'] = $ord['youhui'];
- }
- if(!empty($ord['saoma']) && $ord['saoma'] != '0.00'){
- $payWay['saoma'] = $ord['saoma'];
- }
- if(!empty($ord['hengcheng']) && $ord['hengcheng'] != '0.00'){
- $payWay['hengcheng'] = $ord['hengcheng'];
- }
- if(!empty($ord['jiedai']) && $ord['jiedai'] != '0.00'){
- $payWay['jiedai'] = $ord['jiedai'];
- }
- if(!empty($ord['yunPOS']) && $ord['yunPOS'] != '0.00'){
- $payWay['yunPOS'] = $ord['yunPOS'];
- }
- if(!empty($ord['koubei']) && $ord['koubei'] != '0.00'){
- $payWay['koubei'] = $ord['koubei'];
- }
- if(!empty($ord['dianzijuan']) && $ord['dianzijuan'] != '0.00'){
- $payWay['dianzijuan'] = $ord['dianzijuan'];
- }
- if(!empty($ord['guazhang']) && $ord['guazhang'] != '0.00'){
- $payWay['guazhang'] = $ord['guazhang'];
- }
- if(!empty($ord['qita']) && $ord['huiyuanka'] != '0.00'){
- $payWay['qita'] = $ord['qita'];
- }
- if(!empty($ord['shoujiweixin']) && $ord['shoujiweixin'] != '0.00'){
- $payWay['shoujiweixin'] = $ord['shoujiweixin'];
- }
- return $payWay;
- }
- /*
- * 预购商品保存至文件
- *
- *
- * $product_list = array(
- * 0 => array(
- * 'product_id' => '商品ID',
- * 'num' => '预购数量',
- * )
- * )
- * $model 表名
- * $order_num 订单号
- * $storage_id 仓库
- * */
- static function AddAdvance($model,$order_num,$storage_id,$product_list){
- if(!empty($product_list)){
- $logic = new \app\admins\logic\Purchase;
- $product_ids = join(',',array_column($product_list,"product_id"));
- $where = "storage_id = '{$storage_id}' and product_id in ($product_ids)";
- $list = $logic->getListModel("product_storage", $where);
- foreach($product_list as $k1=>$v1){
- foreach($list as $k2=>$v2){
- if($v1['product_id'] == $v2['product_id']){
- $product_list[$k1]['stock'] = $v2['stock'];
- $product_list[$k1]['advance_num'] = $v2['advance_num'];
- }
- }
- }
- $data = array(
- 'model' => $model,
- 'order_num' => $order_num,
- 'add_time' => date('Y-m-d H:i:s'),
- 'store_id' => Cookie::get('admin_control_store'),
- 'storage_id' => $storage_id,
- 'product_list'=> $product_list,
- );
- if(!file_exists('advance')){
- mkdir ('advance',0777,true);
- }
- $str = json_encode($data);
- $day = 'advance/'.date("Y-m-d");
- file_put_contents($day, $str."^", FILE_APPEND);
- }
- }
- //查询活动信息
- static function actInfo($actid,$ordId){
- $id = array();
- $num = array();
- $newInfos = array();
- $where['id'] = $actid;
- $logic = new \app\admins\logic\Activitycombo();
- $ord = $logic->activityInfos('user_order', "id = {$ordId}", 'act_type', 'id desc', true);
- if($ord['act_type'] == 2 || $ord['act_type'] == 6){
- return true;
- }
- $info = $logic->activityInfos('act_content',$where,'act_type_id,bound_act_id','id desc',true);
- if($info['act_type_id'] != 4){
- return true;
- }
- //虚拟套餐查询绑定的商品套餐,获取商品套餐内容
- $where['id'] = $info['bound_act_id'];
- $re = $logic->activityInfos('act_content',$where,'include','id desc',true);
- $res = explode('&', $re['include']);
- foreach ($res as $kk => $vv) {
- $ids = explode(';', $vv);
- $id[] = explode('=', $ids[0])[1];
- $num[] = explode('=', $ids[2])[1];
- }
- //查询商品信息
- foreach ($id as $key => $val) {
- $fields = 'id,nameer as name,price,pro_category as type,intro as goods_desc,pro_avatar as imgPath';
- $gInfo = $logic->activityInfos('product', array('id'=>$val), $fields,'id desc',true);
- $gInfo['num'] = $num[$key];
- $gInfo['goods_source'] = 2;
- $gInfo['act_id'] = $actid;
- $newInfos[] = [
- 'goods_id' => $gInfo['id'],
- 'goods_name' => $gInfo['name'],
- 'goods_price' => $gInfo['price'],
- 'goods_num' => $gInfo['num'],
- 'goods_type' => $gInfo['type'],
- 'goods_img' => $gInfo['imgPath'],
- 'goods_desc' => $gInfo['goods_desc'],
- 'goods_source' => $gInfo['goods_source'],
- 'act_id' => $actid,
- 'sum_price' => $gInfo['price']*$gInfo['num'],
- 'ord_id' => $ordId
- ];
- }
- if(!empty($newInfos)){
- $insert = Db::name('user_order_goods')->insertAll($newInfos);
- if(!$insert){
- return false;
- }
- }
- return true;
- }
-
- //是否断电 返回true就是不可预定 false就是可以预定
- public function interrupt($store_id,$start_time,$stop_time){
- $logic = new \app\admins\logic\PubliclyOwned;
- $info = $logic->getInfoModel("set_predetermine", "shop_id = $store_id and status = 1 and outage = 2");
- if($info){
- // echo $info['start_time'].'*'.$start_time.'<br>'.$info['stop_time'].'*'.$stop_time;
- if( ($info['start_time']>=$start_time && $info['stop_time']<=$stop_time)
- || ($info['start_time'] <= $start_time && $info['stop_time']>=$stop_time)
- || ($info['stop_time']>=$start_time && $info['stop_time']<=$stop_time && $info['start_time']<=$start_time)
- || ($info['stop_time']>=$start_time && $info['stop_time']>=$stop_time && $info['start_time']<=$stop_time)
- ){
- return array("msg"=>$info,"type"=>"error");
- }
- }
- return array("type"=>"success");
-
- }
- //获取到期时间
- static public function ExpiryTime($start, $end){
- $expTime = null;
- if($start < $end){
- $df = date_diff(date_create($start), date_create($end));
- if($df->y){
- $expTime.=$df->y.'年';
- }
- if($df->m){
- $expTime.=$df->m.'月';
- }
- if($df->d){
- $expTime.=$df->d.'日';
- }
- if($df->h){
- $expTime.=$df->h.'时';
- }
- if($df->i){
- $expTime.=$df->i.'分';
- }
- if($df->s){
- $expTime.=$df->s.'秒';
- }
- }else{
- $expTime = '已到期';
- }
- return $expTime;
- }
-
- //卡卷核销
- static public function AuthenticationCode($code){
- $WxToken = new \app\wechat\service\WxToken;
- $token = $WxToken->kev_getToken();
- $url = "https://api.weixin.qq.com/card/code/consume?access_token=".$token;
- $data = array(
- "code" => $code
- );
- $result = $WxToken->https_request($url,json_encode($data));
- return $result;
- }
-
-
- //获取短信发送
- static public function send($tel, $send)
- {
- if (is_numeric($tel) && strlen($tel) == 11) {
- $cc = '盛世欢唱提醒您:' . $send;
- $zn = iconv("UTF-8", "GB2312//IGNORE", $cc);
- $url = 'http://111.111.111.111:9050/cgi-bin/sendsms?username=sshc@sshc&password=******' . $tel . '&text=' . $zn . '&subid=&msgtype=4';
- //$url = 'http://gateway.iems.net.cn/GsmsHttp?username=69833:admin&password=07914498&from=&to=' . $tel . '&content=' . $zn . '&presendTime=&expandPrefix=';
- self::curl($url);
- }
- }
- //万能curl
- static public function curl($url, $data = null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- if (!empty($data)) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- $out = curl_exec($ch);
- curl_close($ch);
- return json_decode($out, true);
- }
-
- //得到相应会员卡等级积分
- static public function GetGradeIntegral($grade_id=0){
- $integral = 1;
- if($grade_id > 0){
- $logic = new \app\admins\logic\PubliclyOwned;
- $info = $logic->getInfoModel("set_card_grade","id = $grade_id","integral");
- $integral = $info['integral']?$info['integral']:$integral;
- }
- return $integral;
- }
-
-
- /**
- * 发送卡卷
- * store_id 门店ID
- * send_type 发送类型 2充值 1消费
- * price 充值/消费 金额
- * user_id 用户ID
- * type 得到卡卷类型 0 得到微信与铁壶卡卷 1 得到微信卡卷 2 得到铁壶卡卷
- * **/
- static public function SendingCoupon($store_id,$send_type,$price,$user_id,$type){
- $logic = new \app\admins\logic\Coupon();
- $coupon_list = $logic->getCouponList($send_type,$price,$store_id,$user_id,$type);
- if($coupon_list){
- $coupon_list = array_values($coupon_list);
- $coupon_info = $coupon_list[0];
- $data = array(
- "user_id" => $user_id,
- "add_time" => date('Y-m-d H:i'),
- "coupon_id"=> $coupon_info['id'],
- "code" => rand(10,99).time(),
- "status" => 0,
- );
- if($coupon_info['time_type'] == 1){
- $data['start_time'] = $coupon_info['start_time'];
- $data['stop_time'] = $coupon_info['stop_time'];
- }else{
- $data['start_time'] = date('Y-m-d H:i');
- $data['stop_time'] = date('Y-m-d H:i',time()+$coupon_info['day']*86400);
- }
- $result = $logic->AddModel("user_coupon", $data);
- if($result){
- $logic->UpdateModel("coupon", "id={$coupon_info['id']}", array('number'=>$coupon_info['number']-1));
- return $result;
- }
- return false;
- }else{
- return false;
- }
- }
- //获取管理员信息
- static function GetAdmInfo($id, $fields){
- $adm = new ModelUserAdmin();
- return $adm->getFind('admin', "id = {$id}", $fields);
- }
- }
|