Common.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103
  1. <?php
  2. namespace app\admins\service;
  3. use app\admins\model\Admin as ModelUserAdmin;
  4. use app\admins\model\StoreBox as StoreBoxModel;
  5. use app\admins\model\Product as ProductModel;
  6. use think\Cache;
  7. use think\Cookie;
  8. use think\Db;
  9. //服务工具类
  10. class Common
  11. {
  12. public $show_error = "";
  13. //获取管理员拥有门店
  14. static function getStores()
  15. {
  16. $model = new StoreBoxModel();
  17. return $model->getList('store', 'status = 1', 'id ,name');
  18. }
  19. /**
  20. * 获取门店包厢分类
  21. * @param null $stoId
  22. * @param null $customer @按客服端显示
  23. * @return array
  24. */
  25. static function stoBoxTypes($stoId = null, $customer = null)
  26. {
  27. $model = new StoreBoxModel();
  28. if ($stoId) {
  29. $where = "sto_id = {$stoId}";
  30. } else {
  31. $where = "id > 0";
  32. }
  33. if ($customer) {
  34. $where .= ' and status = 1 and show_scope in (1, 2)';
  35. }
  36. $list = $model->getList('store_box_type', $where, 'id, name');
  37. $bt = [];
  38. if (!empty($list)) {
  39. $bt = array_column($list, 'name', 'id');
  40. }
  41. return $bt;
  42. }
  43. //获取区域信息
  44. static function getRegionAddress($pid)
  45. {
  46. $model = new ModelUserAdmin();
  47. return $model->getList('china_region', "code != 0 and pid = {$pid}", null, 'id asc');
  48. }
  49. //获取省市区域指定字段
  50. static function getPCA($pid)
  51. {
  52. $model = new ModelUserAdmin();
  53. return $model->getList('china_region', "code != 0 and pid = {$pid}", 'code, name', 'id asc');
  54. }
  55. //日志类型
  56. const LOG_ADD = 1; //添加
  57. const LOG_REMOVE = 2;//删除
  58. const LOG_UPDATE = 3;//更新
  59. const LOG_LOGIN = 4;//登录
  60. const LOG_EXIT = 5;//退出
  61. //获取日志描述
  62. static function logOptTxt()
  63. {
  64. return [
  65. self::LOG_ADD => '添加',
  66. self::LOG_REMOVE => '删除',
  67. self::LOG_UPDATE => '更新',
  68. self::LOG_LOGIN => '登录',
  69. self::LOG_EXIT => '退出',
  70. ];
  71. }
  72. /*
  73. * 添加日志
  74. * $tableName 表名
  75. * $type 类型 (1.添加 2.删除 3.修改 4.登录 5退出)
  76. * $content 操作描述id+其它
  77. * $details 详情数据
  78. * $column 操作栏目
  79. * */
  80. static function addOperation($tableName, $type, $content = false, $details = null, $column = null)
  81. {
  82. $data = array(
  83. "tb_name" => $tableName,
  84. "type" => $type,
  85. "column" => $column,
  86. "content" => $content,
  87. "details" => $details,
  88. "adm_id" => Cookie::get('admin_id'),
  89. "dt" => date('Y-m-d H:i:s'),
  90. "ip" => $_SERVER['REMOTE_ADDR'],
  91. );
  92. if (!file_exists('journal')) {
  93. mkdir('journal', 0777, true);
  94. }
  95. $str = json_encode($data);
  96. $day = 'journal/' . date("Y-m-d");
  97. file_put_contents($day, $str . "^", FILE_APPEND);
  98. }
  99. //记录管理员操作日志
  100. static function logs($content)
  101. {
  102. $model = new ModelUserAdmin();
  103. $data['adm_id'] = Cookie::get('admin_id');
  104. $data['opera_content'] = $content;
  105. $data['ip'] = $_SERVER['REMOTE_ADDR'];
  106. $data['execute_time'] = date('Y-m-d H:i:s');
  107. $model->addUpdate("admin_log", $data);
  108. }
  109. /**
  110. * 分解时间段
  111. * @param $staTime @开始时间
  112. * @param $endTime @结束时间
  113. * @param $hour @时间划分单位
  114. * @return array
  115. */
  116. static function splitTimeInt($staTime, $endTime, $hour)
  117. {
  118. $staTimeTime = strtotime($staTime);
  119. $entTimeTime = strtotime($endTime);
  120. $timeSlot = $hour * 3600;
  121. $pakNum = ceil(($entTimeTime - $staTimeTime) / $timeSlot);
  122. //小时包计算
  123. $pakData = [];
  124. $basLoop = $staTimeTime;
  125. while ($pakNum) {
  126. $data['s'] = date('Y-m-d H:i', $basLoop);
  127. $basLoop = $basLoop + $timeSlot;
  128. $data['e'] = date('Y-m-d H:i', $basLoop);
  129. $data['h'] = $hour;
  130. $data['u'] = 1;
  131. $data['t'] = 4;
  132. $pakData[] = $data;
  133. $pakNum--;
  134. }
  135. return $pakData;
  136. }
  137. /**
  138. * 获取门店包厢欢唱时间段
  139. * @param $stoId @门店id
  140. * @param $selDate @选择日期
  141. * @return array
  142. */
  143. static function boxTimeInt($stoId, $selDate)
  144. {
  145. //获取门店包厢设定小时段
  146. $model = new \app\admins\model\Common();
  147. $result = $model->getFind('set_bao_reserve', "shop_id = {$stoId} and genre = 4 and status = 1 and del_status = 1",
  148. 'start, finish, hour');
  149. if (empty($result['start']) || empty($result['finish']) || empty($result['hour'])) {
  150. return null;
  151. }
  152. $staTime = $selDate . ' ' . $result['start'];
  153. $endTime = $selDate . ' ' . $result['finish'];
  154. $staTimeTime = strtotime($staTime);
  155. $entTimeTime = strtotime($endTime);
  156. //结束时间改为第二天
  157. if ($entTimeTime < $staTimeTime) {
  158. $entTimeTime = $entTimeTime + 86400;
  159. }
  160. $timeSlot = $result['hour'] * 3600;
  161. $pakNum = floor(($entTimeTime - $staTimeTime) / $timeSlot);
  162. //小时包计算
  163. $pakData = [];
  164. $basLoop = $staTimeTime;
  165. while ($pakNum) {
  166. $data['s'] = date('Y-m-d H:i', $basLoop);
  167. $basLoop = $basLoop + $timeSlot;
  168. $data['e'] = date('Y-m-d H:i', $basLoop);
  169. $data['h'] = $result['hour'];
  170. $data['u'] = 1;
  171. $data['t'] = 4;
  172. $pakData[] = $data;
  173. $pakNum--;
  174. }
  175. return $pakData;
  176. }
  177. /**
  178. * 获取门店包厢欢唱包场时间段
  179. * @param $stoId @门店id
  180. * @param $selDate @选择时间
  181. * @param $allField @获取所以时段
  182. * @return array
  183. */
  184. static function boxWholeInt($stoId, $selDate = null, $allField = 0)
  185. {
  186. $model = new \app\admins\model\Common();
  187. if($allField){
  188. $list = $model->getList('set_bao_reserve', "shop_id = {$stoId}", 'alias, price, hour, genre, start, finish ', 'genre asc');
  189. }else{
  190. $list = $model->getList('set_bao_reserve', "shop_id = {$stoId} and genre != 4 and status = 1 and del_status = 1",
  191. 'alias, price, hour, genre, start, finish ', 'genre asc');
  192. }
  193. $bcTimeSlot = [];
  194. foreach ($list as $k => $v) {
  195. //包场名称
  196. if ($v['genre'] == 1) {
  197. $cd['n'] = $v['alias'] ? $v['alias'] : '上午场';
  198. } else if ($v['genre'] == 2) {
  199. $cd['n'] = $v['alias'] ? $v['alias'] : '下午场';
  200. } else if ($v['genre'] == 3) {
  201. $cd['n'] = $v['alias'] ? $v['alias'] : '全天场';
  202. }
  203. //开始时间
  204. $cd['s'] = substr($selDate . ' ' . $v['start'], 0, 16);
  205. //结束时间
  206. $cd['e'] = substr($selDate . ' ' . $v['finish'], 0, 16);
  207. //获取小时数
  208. $s = strtotime($cd['s']);
  209. $e = strtotime($cd['e']);
  210. if ($s > $e) {
  211. $cd['e'] = date('Y-m-d H:i', strtotime($cd['e']) + 86400);
  212. }
  213. //欢唱时段
  214. $cd['h'] = self::getHour(strtotime($cd['e']) - strtotime($cd['s']));
  215. $cd['u'] = 1;
  216. //场次
  217. $cd['t'] = $v['genre'];
  218. $bcTimeSlot[] = $cd;
  219. }
  220. return $bcTimeSlot;
  221. }
  222. static function getHour($time)
  223. {
  224. return $time / 3600;
  225. }
  226. //返回小时数
  227. /**
  228. * 获取可预定包厢时段
  229. * @param $array1 @门店包厢时段
  230. * @param $array2 @门店包厢预定时段
  231. * @param $selDate @选择查询日期
  232. * @return mixed
  233. */
  234. static function flagRepeatArray($array1, $array2, $selDate, $timeWay)
  235. {
  236. $today = date('Y-m-d');
  237. $now = time();
  238. //选择昨天以前
  239. if ($today > $selDate) {
  240. foreach ($array1 as $k => $v) {
  241. $array1[$k]['u'] = 0;
  242. }
  243. } else {
  244. foreach ($array1 as $k => $v) {
  245. //查询今天
  246. $boxTime = strtotime($today . ' ' . $v['s']);
  247. if (($today == $selDate) && ($now > $boxTime)) {
  248. $array1[$k]['u'] = 0;
  249. } else {
  250. foreach ($array2 as $k1 => $v1) {
  251. $st = $selDate . ' ' . $v['s'] . ':00';
  252. $st = substr($st, 0, 19);
  253. $et = $selDate . ' ' . $v['e'] . ':00';
  254. $et = substr($et, 0, 19);
  255. if ($timeWay) {//包场判断
  256. if (($v1['s'] >= $st) && ($v1['s'] < $et)) {
  257. $array1[$k]['u'] = 0;
  258. }
  259. } else {//自由判断
  260. if (($st == $v1['s'])) {
  261. $array1[$k]['u'] = 0;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. return $array1;
  269. }
  270. //获取毫秒时间戳
  271. static function getMillisecond()
  272. {
  273. list($t1, $t2) = explode(' ', microtime());
  274. return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
  275. }
  276. //生成订单号(日期(年月日时分秒)拼上用户id)订单号总长度规定23位,不够用随机数补位
  277. static function getOrdNum($uid)
  278. {
  279. //生成订单号(日期(年月日时分秒)拼上用户id)订单号总长度规定23位,不够用随机数补位
  280. $ord_num = date("YmdHis", time()) . $uid;
  281. $num = 23 - (strlen($ord_num));
  282. $ord_num .= rand(str_pad(1, $num, 0, STR_PAD_RIGHT), str_pad(9, $num, 9, STR_PAD_RIGHT));
  283. return $ord_num;
  284. }
  285. //vod开关机
  286. /*$ordType 订单类型 1正常 2续时 3换房 30换房后 31线下换房 32线下换房后 4退款' */
  287. static function vodBoot($hmUrl, $hmId, $switch = 1,$actId = '',$ordId='',$ordType=0)
  288. {
  289. if ($switch) {
  290. if ($actId != '') {
  291. if (Cache::get($actId . $ordId) != 1) {
  292. $actInsert = self::actInfo($actId, $ordId);
  293. if (!$actInsert) {
  294. $data['status'] = 0;
  295. $data['msg'] = '虚拟套餐有误';
  296. return $data;
  297. } else {
  298. Cache::set($actId . $ordId, 1, 3600 * 24);
  299. }
  300. }
  301. }
  302. }
  303. $data['status'] = 1;
  304. $data['msg'] = '开机成功';
  305. return $data;
  306. //获取签名
  307. $sData['boxid'] = $hmId;
  308. $sData['random'] = time();
  309. $sign = self::genSign($sData);
  310. //开机接口
  311. if ($switch) {
  312. $hmUrl .= '/StartRoom?boxid=' . $hmId . '&random=' . $sData['random'] . '&sign=' . $sign;
  313. } else {//关机
  314. $hmUrl .= '/CloseRoom?boxid=' . $hmId . '&random=' . $sData['random'] . '&sign=' . $sign;
  315. }
  316. $ch = curl_init();
  317. curl_setopt($ch, CURLOPT_URL, $hmUrl);
  318. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  319. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  320. if (!empty($data)) {
  321. curl_setopt($ch, CURLOPT_POST, 1);
  322. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  323. }
  324. $out = curl_exec($ch);
  325. curl_close($ch);
  326. //判断返回的数据是否是xml
  327. $re = xml_parse(xml_parser_create(), $out);
  328. if (!$re) {
  329. $data['status'] = '-1';
  330. $data['msg'] = '请求地址错误';
  331. return $data;
  332. }
  333. $xml = simplexml_load_string($out);
  334. $xmlJson = json_encode($xml);
  335. $arr = json_decode($xmlJson, true);
  336. if ($switch) {
  337. if (!empty($arr['StartRoomINFO']['STATUS'])) {
  338. //检查活动套餐添加详情
  339. if ($actId != '') {
  340. if (Cache::get($actId . $ordId) != 1) {
  341. $actInsert = self::actInfo($actId, $ordId);
  342. if ($actInsert) {
  343. Cache::set($actId . $ordId, 1, 3600 * 24);
  344. }
  345. }
  346. }
  347. $data['status'] = 1;
  348. $data['msg'] = '开机成功';
  349. } else if (!empty($arr['ERROR'])) {
  350. //检查活动套餐添加详情
  351. if ($actId != '') {
  352. if (Cache::get($actId . $ordId) != 1) {
  353. $actInsert = self::actInfo($actId, $ordId);
  354. if ($actInsert) {
  355. Cache::set($actId . $ordId, 1, 3600 * 24);
  356. }
  357. }
  358. }
  359. $data['status'] = 2;
  360. $data['msg'] = '已开机';
  361. } else {
  362. $data['status'] = 0;
  363. $data['msg'] = '开机失败,请联系工作人员';
  364. }
  365. } else {
  366. if (!empty($arr['CloseRoomINFO']['STATUS'])) {
  367. $data['status'] = 1;
  368. $data['msg'] = '关机成功';
  369. } else if (!empty($arr['ERROR'])) {
  370. $data['status'] = 2;
  371. $data['msg'] = '已关机';
  372. } else {
  373. $data['status'] = 0;
  374. $data['msg'] = '关机失败,请联系工作人员';
  375. }
  376. }
  377. return $data;
  378. }
  379. //调取签名接口
  380. static function genSign($url, $plus = null)
  381. {
  382. //删除签名参数
  383. unset($url['sign']);
  384. //升序排序参数
  385. ksort($url);
  386. //加盐参数
  387. $salt = '---happyktv';
  388. //拼接加密url
  389. $encUrl = null;
  390. foreach ($url as $k => $v) {
  391. $encUrl .= $encUrl ? '&' . $k . '=' . $v : $k . '=' . $v;
  392. }
  393. //md5签名 获取包厢类型时加盐
  394. if ($plus) {
  395. $encUrl = $salt . $encUrl;
  396. }
  397. $sign = md5($encUrl);
  398. return $sign;
  399. }
  400. /**
  401. * 获取包厢相关价格
  402. * @param $stoId @门店
  403. * @param $boxType @包厢类型
  404. * @param $screenings @场次
  405. * @param $actId @活动id
  406. * @param $selDate @查询日期
  407. * @param $source @来源
  408. * @return false|\PDOStatement|string|\think\Collection
  409. */
  410. static function boxPricing($stoId, $boxType, $screenings, $actId, $selDate, $source = 0)
  411. {
  412. $model = new \app\admins\model\Common();
  413. $where = "sto_id = {$stoId} and sto_type_id = {$boxType} and
  414. field_id = {$screenings} and act_id = {$actId} and use_status = 1 and del_status = 1";
  415. if($source == 1){
  416. $where.= ' and wx_show = 1';
  417. }
  418. //获取包厢相关定价
  419. $bp = $model->getFind('box_price', $where, 'id, up_price, down_price, act_id, minus_id');
  420. //获取包厢数据加价
  421. if ($bp) {
  422. $where = "box_price_id = {$bp['id']} and use_status = 1 and del_status = 1";
  423. if($source == 1){
  424. $where.= ' and wx_show = 1';
  425. }
  426. $jj = $model->getList('box_chase_price', $where, 'id, time, up_price, down_price');
  427. foreach ($jj as $k => $v) {
  428. $dates = explode(',', $v['time']);
  429. foreach ($dates as $k1 => $d) {
  430. if ($selDate == $d) {
  431. $bp['up_price'] = $bp['up_price'] + $v['up_price'];
  432. $bp['down_price'] = $bp['down_price'] + $v['down_price'];
  433. break;
  434. }
  435. }
  436. }
  437. }
  438. return $bp;
  439. }
  440. /**
  441. * 最新获取包厢相关价格
  442. * @param $stoId @门店
  443. * @param $boxType @包厢类型
  444. * @param $screenings @场次
  445. * @param $actId @活动id
  446. * @param $selDate @查询日期
  447. * @param $source @来源
  448. * @return false|\PDOStatement|string|\think\Collection
  449. */
  450. static function boxPricingNewest($stoId, $boxType, $screenings, $actId, $selDate)
  451. {
  452. $model = new \app\admins\model\Common();
  453. $where = "sto_id = {$stoId} and sto_type_id = {$boxType} and
  454. field_id = {$screenings} and act_id = {$actId} and use_status = 1 and del_status = 1";
  455. //获取包厢相关定价
  456. $bp = $model->getFind('box_price', $where, 'id, up_price, down_price, act_id, minus_id, wx_show');
  457. //获取包厢数据加价
  458. if ($bp) {
  459. $where = "box_price_id = {$bp['id']} and use_status = 1 and del_status = 1";
  460. $jj = $model->getList('box_chase_price', $where, 'id, time, up_price, down_price, wx_show');
  461. foreach ($jj as $k => $v) {
  462. $dates = explode(',', $v['time']);
  463. foreach ($dates as $k1 => $d) {
  464. if ($selDate == $d) {
  465. $bp['up_price'] = $bp['up_price'] + $v['up_price'];
  466. $bp['down_price'] = $bp['down_price'] + $v['down_price'];
  467. $bp['wx_show'] = $v['wx_show'];
  468. break;
  469. }
  470. }
  471. }
  472. }
  473. return $bp;
  474. }
  475. //获取包场不同类型房间价格
  476. static function boxTypePrice($stoId, $boxType, $screenings)
  477. {
  478. $model = new \app\admins\model\Common();
  479. return $model->getFind('set_bao_reserve_price', "shop_id = {$stoId} and box_type = {$boxType} and genre = {$screenings}",
  480. 'id, price, un_line_price');
  481. }
  482. //查询订单退款比例规则
  483. /*
  484. * $stoId 门店id
  485. * */
  486. static function ref_role($stoId, $type)
  487. {
  488. // $where['shop_id'] = $stoId;
  489. $where['genre'] = $type;
  490. $table = 'set_refund_ratio';
  491. $filed = 'start,finish,ratio';
  492. $model = new \app\admins\model\Common();
  493. $re = $model->getList($table, $where, $filed);
  494. $ratio = 100;
  495. //获取当前时间的年月日
  496. $date = date('Y-m-d');
  497. //获取当前时间戳
  498. $time = time();
  499. $aEndTime = array();
  500. //将查询出的时间进行拼接日期比较获取响应的扣款比例
  501. foreach ($re as $k => $v) {
  502. $startTime = strtotime($date . ' ' . $v['start']);
  503. $endTime = strtotime($date . ' ' . $v['finish']);
  504. if ($endTime < $startTime) {
  505. $endTime = $endTime + (24 * 60 * 60);
  506. }
  507. $aEndTime['endTime'][] = $endTime;
  508. }
  509. $maxEndTime = strtotime($date . ' ' . date('H:i:s', max($aEndTime['endTime'])));
  510. $maxYEndTime = date('Y-m-d', max($aEndTime['endTime']));
  511. if ($time < $maxEndTime && $maxYEndTime > $date) {
  512. $date = date('Y-m-d', strtotime($date) - (24 * 60 * 60));
  513. }
  514. foreach ($re as $k => $v) {
  515. $startTime = strtotime($date . ' ' . $v['start']);
  516. $endTime = strtotime($date . ' ' . $v['finish']);
  517. if ($endTime < $startTime) {
  518. $endTime = $endTime + (24 * 60 * 60);
  519. }
  520. //判断当前时间是否在查询出来的时间段内
  521. if ($time < $startTime) {
  522. $ratio = 0;
  523. } else if ($startTime <= $time && $time <= $endTime + 59) {
  524. $ratio = $v['ratio'];
  525. echo $ratio;
  526. break;
  527. } else if ($time > $endTime) {
  528. $ratio = 100;
  529. }
  530. }
  531. return $ratio;
  532. //将查询出的时间进行拼接日期比较获取响应的扣款比例
  533. }
  534. //获取指定门店场次
  535. static function stoScreenings($stoId)
  536. {
  537. if (empty($stoId)) {
  538. return null;
  539. }
  540. $model = new StoreBoxModel();
  541. return $model->getList('set_bao_reserve', "shop_id = {$stoId} and status = 1 and del_status = 1",
  542. 'id ,genre, start, finish, alias', 'genre asc');
  543. }
  544. //套餐详情查询失败返回false
  545. static function goodsInfo($id, $filed = '*')
  546. {
  547. $model = new StoreBoxModel();
  548. $where['id'] = $id;
  549. $re = $model->getFind('act_content', $where, 'include,cost_price,up_price,down_price');
  550. if (empty($re)) {
  551. return false;
  552. }
  553. //切割字符串成数组
  554. $array = array();
  555. $arr = explode('&', $re['include']);
  556. foreach ($arr as $k => $v) {
  557. $_arr = explode(';', $v);
  558. foreach ($_arr as $kk => $vv) {
  559. $a = explode("=", $vv);
  560. $array[$k][$a[0]] = $a[1];
  561. }
  562. }
  563. $goodsInfo = array();
  564. $goodsInfo['act_cost_price'] = $re['cost_price'];
  565. $goodsInfo['act_up_price'] = $re['up_price'];
  566. $goodsInfo['act_down_price'] = $re['down_price'];
  567. foreach ($array as $k => $v) {
  568. //查询商品信息
  569. $where['id'] = $v['gid'];
  570. $res = $model->getFind('product', $where, $filed);
  571. $goodsInfo['info'][$k] = $res;
  572. //查询商品类型
  573. $where['id'] = $v['tid'];
  574. $type = $model->getFind('product_category', $where, 'shop_name');
  575. $goodsInfo['info'][$k]['type_name'] = $type['shop_name'];
  576. $goodsInfo['info'][$k]['act_num'] = $v['num'];
  577. }
  578. return $goodsInfo;
  579. }
  580. //获取门店场次时间
  581. static function stoTimePeriod($stoId, $genre)
  582. {
  583. if (empty($stoId)) {
  584. return null;
  585. }
  586. $model = new StoreBoxModel();
  587. return $model->getFind('set_bao_reserve', "shop_id = {$stoId} and genre = {$genre} and status = 1 and del_status = 1",
  588. 'id , start, finish');
  589. }
  590. /**
  591. * 获取活动套餐产品id,数量
  592. * @param $proSource @产品源信息
  593. * @return array
  594. */
  595. static function actProInfo($proSource)
  596. {
  597. //活动产品
  598. $actPros = null;
  599. if (empty($proSource)) {
  600. return $actPros;
  601. }
  602. $yPro = explode('&', $proSource);
  603. $yyCp = [];
  604. $a1 = [];
  605. foreach ($yPro as $k => $v) {
  606. $yPros = explode(';', $v);
  607. $a1[] = $yPros[0];
  608. $a1[] = $yPros[2];
  609. $yyCp[] = $a1;
  610. $a1 = null;
  611. }
  612. foreach ($yyCp as $v1) {
  613. $aa = explode('=', $v1[0]);
  614. $bb = explode('=', $v1[1]);
  615. $yp['id'] = $aa[1];
  616. $yp['num'] = $bb[1];
  617. $actPros[] = $yp;
  618. $yp = null;
  619. }
  620. return $actPros;
  621. }
  622. /**
  623. * 获取应补套餐
  624. * @param $yyCp @小包厢套餐
  625. * @param $xxCp @大包厢套餐
  626. * @return array|int|null
  627. */
  628. static function supplyMeal($yyCp, $xxCp)
  629. {
  630. //检查套餐设置是否正确
  631. $tag = 0;
  632. //应补产品
  633. $nPro = null;
  634. //检查产品数量
  635. $a = 0;
  636. if(!empty($yyCp)){
  637. foreach($yyCp as $v){
  638. $a = $a + $v['num'];
  639. }
  640. }
  641. //检查产品数量
  642. $b = 0;
  643. if(!empty($xxCp)){
  644. foreach($xxCp as $v){
  645. $b = $b + $v['num'];
  646. }
  647. }
  648. //大换小
  649. if($a > $b){
  650. $temp = $yyCp;
  651. $yyCp = $xxCp;
  652. $xxCp = $temp;
  653. }
  654. if (!empty($yyCp) && !empty($xxCp)) {
  655. foreach ($yyCp as $v) {
  656. $have = 0;
  657. foreach ($xxCp as $v1) {
  658. if ($v['id'] == $v1['id']) {
  659. $have = 1;
  660. }
  661. }
  662. if (!$have) {
  663. $tag = 1;
  664. break;
  665. }
  666. }
  667. }
  668. //小换大,获取应补产品
  669. if ($a < $b && !$tag) {
  670. foreach ($xxCp as $v1) {
  671. $data['id'] = $v1['id'];
  672. $data['num'] = $v1['num'];
  673. if (!empty($yyCp)) {
  674. foreach ($yyCp as $v) {
  675. if ($v1['id'] == $v['id']) {
  676. $data['num'] = $v1['num'] - $v['num'];
  677. if ($data['num'] < 0) {
  678. $tag = 1;
  679. }
  680. }
  681. }
  682. }
  683. if($data['num'] > 0){
  684. $nPro[] = $data;
  685. }
  686. $data = null;
  687. }
  688. }
  689. if ($tag) {
  690. return -1;
  691. }
  692. return $nPro;
  693. }
  694. /**
  695. * 获取商品活动套餐商品明细
  696. * @param $ordId @订单id
  697. * @param $actType @活动类型 1普通商品 2活动套餐 3商品套餐 4增值服务 5换酒
  698. * @return false|\PDOStatement|string|\think\Collection
  699. */
  700. static function ordActPros($ordId, $actType){
  701. $model = new ProductModel();
  702. return $model->getList('user_order_goods', "ord_id = {$ordId} and goods_source = {$actType}", 'goods_id as id, goods_num as num');
  703. }
  704. //库存信息的改变
  705. static function achieve($proId, $count, $genre, $desc)
  706. {
  707. $list = Common::fulfill($proId, $count, $genre);
  708. if ($list) {
  709. $data = Common::information($proId);
  710. Common::proOut($data, $count, $genre, $desc);
  711. //$returnData['status'] = '库存改变成功';
  712. $returnData = 1;
  713. } else {
  714. //$returnData['msg'] = '库存改变失败';
  715. $returnData = 0;
  716. }
  717. return $returnData;
  718. }
  719. /**
  720. * 订单完成改变库存
  721. * @param array $pros @产品id
  722. * @param $storage @仓库id
  723. * @param array $ckType @出口类型 格式['add' => 1,0减库存 1加库存 'type' => 'ys' zs为真实库存 ys为预售库存]
  724. * @return int
  725. */
  726. static function stockHandle($pros, $storage, $ckType)
  727. {
  728. $model = new ProductModel();
  729. //预售出库
  730. if($ckType['type'] == 'ys'){
  731. $field = 'advance_num';
  732. }else{//真实出库
  733. $field = 'stock';
  734. }
  735. $result = 0;
  736. foreach($pros as $v){
  737. $where = "product_id = {$v['id']} and storage_id = {$storage}";
  738. if($ckType['add'] == 1){
  739. $result = $model->table('ktv_product_storage')->where($where) ->setInc($field, $v['num']);
  740. } else{
  741. $result = $model->table('ktv_product_storage')->where($where) ->setDec($field, $v['num']);
  742. }
  743. }
  744. return $result;
  745. }
  746. //查询商品的信息
  747. static function information($pro_id)
  748. {
  749. $model = new ProductModel();
  750. $where = "id = $pro_id";
  751. $filed = 'id,shop_id,pro_coding,nameer,pro_specification,unit,number,pro_category';
  752. return $model->getFind('product', $where, $filed);
  753. }
  754. //出库记录
  755. static function proOut($data, $count, $genre, $desc)
  756. {
  757. $model = new ProductModel();
  758. if ($genre == 1) {
  759. $gen = '-' . $count;
  760. } else {
  761. $gen = '+' . $count;
  762. }
  763. $arr = [
  764. 'ent_id' => $data['id'],
  765. 'shop_id' => $data['shop_id'],
  766. 'genre' => $genre,
  767. 'pro_coding' => $data['pro_coding'],
  768. 'name' => $data['nameer'],
  769. 'pro_specification' => $data['pro_specification'],
  770. 'unit' => $data['unit'],
  771. 'num' => $gen,
  772. 'pro_category' => $data['pro_category'],
  773. 'particulars' => $desc,
  774. 'add_time' => date('Y-m-d H:i:s'),
  775. 'adm_id' => Cookie::get('admin_id')
  776. ];
  777. $bank = $model->addData('warehouse', $arr);
  778. //日志
  779. if ($bank) {
  780. $CAdmBase = new \app\base\CAdmBase;
  781. $centent = $genre == 1 ? '添加出库信息 id:' . $bank : '添加入库信息 id:' . $bank;
  782. $CAdmBase->addOperation("warehouse", 1, $centent);
  783. // if ($genre == 1) {
  784. // Common::logs('添加出库信息 id:' . $bank);
  785. // } else {
  786. // Common::logs('添加入库信息 id:' . $bank);
  787. // }
  788. }
  789. return $bank;
  790. }
  791. //==================================投票代码================================================
  792. //赠送次数添加
  793. static function addNum($uid, $winOrdNum)
  794. {
  795. $model = new ProductModel();
  796. //查询表中是否有uid
  797. $table = 'vote_num';
  798. //查询酒水定单的付款金额
  799. if (!empty($winOrdNum)) {
  800. $where['ord_num'] = $winOrdNum;
  801. $filed = 'amount';
  802. $amount = $model->getFind('user_drinks_order', $where, $filed);
  803. unset($where);
  804. $where['uid'] = $uid;
  805. $num = ceil($amount['amount']);
  806. $re = $model->getFind($table, $where, 'id');
  807. if ($re) {
  808. //有信息直接修改次数
  809. $re = Db::table('ktv_' . $table)->where($where)->setInc('extra_num', $num);
  810. } else {
  811. //没有信息查询用户表在添加到表中
  812. unset($where);
  813. $where['id'] = $uid;
  814. $openid = $model->getFind('user', $where, 'openid');
  815. if (!empty($openid)) {
  816. $data['uid'] = $uid;
  817. $data['openid'] = $openid['openid'];
  818. $data['extra_num'] = $num;
  819. $model->addData($table, $data);
  820. }
  821. }
  822. }
  823. }
  824. //==================================投票代码================================================
  825. //生成采购库存订单号
  826. static function pwOrdNum($prefix)
  827. {
  828. return $prefix . date('Ymds') . rand(1000, 9999);
  829. }
  830. //获取用户openId
  831. static function getOpenIdByUid($uid)
  832. {
  833. $model = new ModelUserAdmin();
  834. return $model->getFind('user', "id = {$uid}", 'openid');
  835. }
  836. /**
  837. * 验证输入的邮件地址是否合法
  838. *
  839. * @param string $email 需要验证的邮件地址
  840. *
  841. * @return bool
  842. */
  843. function if_email($email)
  844. {
  845. $chars = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
  846. if (strpos($email, '@') !== false && strpos($email, '.') !== false) {
  847. if (preg_match($chars, $email)) {
  848. return true;
  849. } else {
  850. return false;
  851. }
  852. } else {
  853. return false;
  854. }
  855. }
  856. /**
  857. * 验证输入的手机号是否正确
  858. * @return boolean
  859. */
  860. function if_mobile($mobile)
  861. {
  862. if (preg_match('/^1(3|4|5|6|7|8|9)[0-9]{9}$/', $mobile)) {
  863. return true;
  864. } else {
  865. return false;
  866. }
  867. }
  868. /**
  869. * 验证输入的电话是否正确
  870. * @return boolean
  871. */
  872. function if_tel($tel)
  873. {
  874. if (preg_match('/^([0-9]{3,4}-)?[0-9]{7,8}$/', $tel)) {
  875. return true;
  876. } else {
  877. return false;
  878. }
  879. }
  880. /*
  881. * 仓库列表 (录入与采购退货)
  882. * $keyword 商品编号或者商品拼音
  883. * $storage_id 仓库ID
  884. * */
  885. static function storage_product_list($keyword, $storage_id = 0)
  886. {
  887. $logic = new \app\admins\logic\Purchase;
  888. $store_id = cookie('admin_control_store');
  889. $where = "b.id != 0 and a.shop_id = '{$store_id}' and a.status = 1 and (a.pro_coding='{$keyword}' or a.spell like '%{$keyword}%')";
  890. $field = "a.id,a.pro_coding,a.nameer,a.unit,a.pro_specification,a.cost,a.spell";
  891. $product_list = $logic->JoinModel("product", "product_category", $where, "a.pro_category=b.id", $field);
  892. foreach ($product_list as $key => $val) {
  893. $info = $logic->getInfoModel("product_storage", "product_id = '{$val['id']}' and storage_id = '{$storage_id}'");
  894. $product_list[$key]['number'] = isset($info) ? $info['stock'] : 0;
  895. }
  896. if ($product_list) {
  897. return $product_list;
  898. } else {
  899. return false;
  900. }
  901. }
  902. /*
  903. * 仓库列表 (库存调拨,报损报溢)
  904. * $keyword 商品编号或者商品拼音
  905. * $storage_id 仓库ID
  906. * */
  907. static function new_storage_product_list($keyword, $storage_id)
  908. {
  909. $logic = new \app\admins\logic\Purchase;
  910. $store_id = cookie('admin_control_store');
  911. $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}%')";
  912. $field = "a.id,a.pro_coding,a.nameer,a.unit,a.pro_specification,a.cost,a.spell,c.stock as number";
  913. $product_list = Db::name("product")
  914. ->alias("a")
  915. ->join("product_category b", "a.pro_category=b.id")
  916. ->join("product_storage c", "a.id=c.product_id")
  917. ->field($field)
  918. ->where($where)
  919. ->select();
  920. if ($product_list) {
  921. return $product_list;
  922. } else {
  923. return false;
  924. }
  925. }
  926. /**
  927. * 添加信息至库存表及库存商品详情
  928. * @param $restocking @string|int 库存类型
  929. * @param $storage_id @string|int 仓库ID
  930. * @param $product_list @array商品信息 (sales_type销售类型(restocking等于8的时候传)real_total_price实际总金额,reference_total_price参考总金额,real_price实际价格,reference_price销售价格 product_id商品ID,amount数量(寄存数量或退单数量),remark备注(商品备注可有可没有))
  931. * @param $remark @string 入库备注信息备注信
  932. * @param $uid
  933. * @param $payable @string 实付价格
  934. * @param $payment @string 应付价格
  935. * @param $thing @string false就是使用事物,true就是不使用事物
  936. * @return bool
  937. */
  938. static function storage_operate_add($restocking, $storage_id, $product_list, $uid = 0, $remark = 0, $payable = 0, $payment = 0,$thing=false)
  939. {
  940. if (!empty($product_list)) {
  941. $model = new \app\admins\model\Purchase;
  942. $logic = new \app\admins\logic\Purchase;
  943. $ord_num = self::pwOrdNum($model->put_type[$restocking]); //生成一个订单号
  944. $time = date("Y-m-d H:i:s");
  945. $data = array(
  946. "ord_num" => $ord_num,
  947. "restocking" => $restocking,
  948. "add_time" => $time,
  949. "storage_id" => $storage_id,
  950. "adm_id" => $uid ? $uid : cookie("admin_id"),
  951. "remark" => $remark,
  952. "payable" => $payable,
  953. "payment" => $payment,
  954. );
  955. return $logic->AddProductPut($data, $product_list, $uid,$thing);
  956. }
  957. return false;
  958. }
  959. //打单处理预售库存与真实库存
  960. /*
  961. * prodcut_list = array(
  962. * storage_id => int 仓库ID
  963. * gid => int 商品ID
  964. * num => int 商品数量
  965. * )
  966. * type 0减
  967. */
  968. static function ProductStorageEdit($product_list = array(),$type=0){
  969. if(empty($product_list) || $type>0){
  970. return false;
  971. }
  972. $logic = new \app\admins\logic\Purchase;
  973. foreach($product_list as $key=>$val){
  974. $where = "storage_id = '{$val['storage_id']}' and product_id = '{$val['gid']}'";
  975. $info = $logic->getInfoModel("product_storage", $where);
  976. if(isset($info)){
  977. if($type == 0){
  978. $data = array(
  979. 'stock' => intval($info['stock']) - intval($val['num']),
  980. 'advance_num'=> intval($info['advance_num']) - intval($val['num']),
  981. );
  982. }
  983. $result = $logic->UpdateModel("product_storage", $where, $data);
  984. }
  985. }
  986. return true;
  987. }
  988. //获取门店销售仓库
  989. static function getSaleStorage($stoId)
  990. {
  991. $store = new StoreBoxModel();
  992. $result = $store->getFind('store', "id = {$stoId}", 'storage_id');
  993. if (!empty($result['storage_id'])) {
  994. return $result['storage_id'];
  995. }
  996. return null;
  997. }
  998. //报表中心导航栏
  999. static function navigation()
  1000. {
  1001. $param = array(
  1002. "put_storage" => array(
  1003. "name" => "入库管理报表",
  1004. "list" => array(
  1005. 0 => array("url" => "/admins/report/put_product", "name" => "商品入库明细表"),
  1006. 1 => array("url" => "/admins/report/put_product_gather", "name" => "商品入库汇总表"),
  1007. 2 => array("url" => "/admins/report/put_storage", "name" => "仓库收货明细表"),
  1008. 3 => array("url" => "/admins/report/put_storage_gather", "name" => "仓库收货汇总汇表"),
  1009. 4 => array("url" => "/admins/report/put_supplier?restocking=1", "name" => "供应商供货明细表"),
  1010. 5 => array("url" => "/admins/report/put_supplier_gather?restocking=1", "name" => "供应商供货汇总表"),
  1011. ),
  1012. ),
  1013. "out_storage" => array(
  1014. "name" => "出库管理报表",
  1015. "list" => array(
  1016. 0 => array("url" => "/admins/report/put_product?do=1", "name" => "商品出库明细表"),
  1017. 1 => array("url" => "/admins/report/put_product_gather?do=1", "name" => "商品出库汇总表"),
  1018. 2 => array("url" => "/admins/report/put_supplier?restocking=2", "name" => "供应商退货明细表"),
  1019. 3 => array("url" => "/admins/report/put_supplier_gather?restocking=2", "name" => "供应商退货汇总表"),
  1020. ),
  1021. ),
  1022. "storage" => array(
  1023. "name" => "库存管理报表",
  1024. "list" => array(
  1025. 0 => array("url" => "/admins/report/allocate_transfer", "name" => "调拨明细表"),
  1026. 1 => array("url" => "/admins/report/allocate_transfer_gather", "name" => "调拨汇总表"),
  1027. 2 => array("url" => "/admins/report/product_check?restocking=6", "name" => "报损明细表"),
  1028. 3 => array("url" => "/admins/report/product_check_gather?restocking=6", "name" => "报损汇总表"),
  1029. 4 => array("url" => "/admins/report/product_check?restocking=7", "name" => "报溢明细表"),
  1030. 5 => array("url" => "/admins/report/product_check_gather?restocking=7", "name" => "报溢汇总表"),
  1031. 6 => array("url" => "/admins/report/product_list", "name" => "商品库存表"),
  1032. ),
  1033. ),
  1034. "finance" => array(
  1035. "name" => "财务报表",
  1036. "list" => array(
  1037. 0 => array("url" => "/admins/finance/business", "name" => "营业账单查询"),
  1038. // 1 => array("url" => "/admins/finance/box", "name" => "包厢消费明细表"),
  1039. 1 => array("url" => "/admins/Reportcontroller/boxDetailList", "name" => "包厢消费明细表"),
  1040. 2 => array("url" => "/admins/finance/kitchen", "name" => "厨房出品明细表"),
  1041. // 3 => array("url" => "/admins/finance/bar_counter", "name" => "吧台营业日报表"),
  1042. 3 => array("url" => "/admins/Reportcontroller/dayReport", "name" => "吧台营业日报表"),
  1043. 4 => array("url" => "/admins/finance/sell", "name" => "商品销售明细表"),
  1044. 5 => array("url" => "/admins/finance/give", "name" => "赠送明细表"),
  1045. 6 => array("url" => "/admins/finance/deposit", "name" => "商品寄存明细表"),
  1046. // 7 => array("url" => "/admins/finance/goodsSum", "name" => "销售汇总"),
  1047. 7 => array("url" => "/admins/Reportcontroller/sellSum", "name" => "销售汇总"),
  1048. 8 => array("url" => "/admins/finance/refaultPriceList", "name" => "退款报表"),
  1049. 9 => array("url" => "/admins/finance/winOrd", "name" => "酒水订单报表"),
  1050. 10 => array("url" => "/admins/Reportcontroller/cardFirst", "name" => "会员首充门店表"),
  1051. ),
  1052. )
  1053. );
  1054. return $param;
  1055. }
  1056. /**
  1057. * 库存数量检查
  1058. * @param $actPros @活动套餐,商品套餐
  1059. * 格式
  1060. * $actPros = [
  1061. ['act_id' => 1, 'amount' => 2, 'storage_id' => 3],
  1062. ['act_id' => 3, 'amount' => 1, 'storage_id' => 3],
  1063. ];
  1064. * @param $comPros @商品信息
  1065. * 格式
  1066. $comPros = [
  1067. ['pro_id' => 3, 'amount' => 10, 'storage_id' => 3],
  1068. ['pro_id' => 4, 'amount' => 1, 'storage_id' => 3],
  1069. ];
  1070. *
  1071. * @return mixed
  1072. */
  1073. static function inventoryCheck($actPros, $comPros)
  1074. {
  1075. //购买产品
  1076. $pros = [];
  1077. $storage = 0; //仓库id
  1078. if (!empty($actPros)) {
  1079. $storage = $actPros[0]['storage_id'];
  1080. if (empty($storage)) {
  1081. echo '套餐未指定仓库id';
  1082. die;
  1083. }
  1084. //获取活动信息
  1085. $model = new ProductModel();
  1086. $ids = join(',', array_column($actPros, "act_id"));
  1087. $list = $model->getList('act_content', "id in ($ids) and act_type_id != 3 and act_type_id != 4", 'id,act_name, include');
  1088. foreach ($list as $k1 => $v1) {
  1089. foreach ($actPros as $k2 => $v2) {
  1090. $v1['id'] == $v2['act_id'] ? $list[$k1]['amount'] = $v2['amount'] : "";
  1091. }
  1092. }
  1093. foreach ($list as $v) {
  1094. //获取活动包含商品
  1095. $actTc = explode('&', $v['include']);
  1096. if (!empty($actTc)) {
  1097. foreach ($actTc as $v1) {
  1098. $pro = explode(';', $v1);
  1099. if (!empty($pro)) {
  1100. $proStr = explode('=', $pro[0]);
  1101. $amountStr = explode('=', $pro[2]);
  1102. if (!empty($proStr)) {
  1103. //购买数据 = 套餐内数量 * 购买套餐数量
  1104. $buyAmount = $amountStr[1] * $v['amount'];
  1105. $t['pro_id'] = $proStr[1];
  1106. $t['pro_amount'] = $buyAmount;
  1107. $t['storage_id'] = $storage;
  1108. //添加产品
  1109. if (empty($pros)) {
  1110. $pros[] = $t;
  1111. } else {
  1112. $isAdd = 0;
  1113. foreach ($pros as $k => $p) {
  1114. //修改产品数量
  1115. if ($p['pro_id'] == $t['pro_id']) {
  1116. $pros[$k]['pro_amount'] = $p['pro_amount'] + $t['pro_amount'];
  1117. $isAdd = 1;
  1118. }
  1119. }
  1120. //添加产品
  1121. if (!$isAdd) {
  1122. $pros[] = $t;
  1123. }
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131. //合并产品中产品数量
  1132. if (!empty($comPros)) {
  1133. foreach ($comPros as $v) {
  1134. $t['pro_id'] = $v['pro_id'];
  1135. $t['pro_amount'] = $v['amount'];
  1136. $t['storage_id'] = $v['storage_id'];
  1137. //添加产品
  1138. if (empty($pros)) {
  1139. $pros[] = $t;
  1140. } else {
  1141. $isAdd = 0;
  1142. foreach ($pros as $k => $p) {
  1143. //修改产品数量
  1144. if ($p['pro_id'] == $t['pro_id']) {
  1145. $pros[$k]['pro_amount'] = $p['pro_amount'] + $t['pro_amount'];
  1146. $isAdd = 1;
  1147. }
  1148. }
  1149. //添加产品
  1150. if (!$isAdd) {
  1151. $pros[] = $t;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. $data['status'] = 0;
  1157. $data['msg'] = null;
  1158. //检查产品库存
  1159. if (!empty($pros)) {
  1160. $model = new ProductModel();
  1161. foreach ($pros as $v) {
  1162. //获取商品信息
  1163. // $pro = $model->getFind('product', "id ={$v['pro_id']}", 'nameer, number');
  1164. $pro = $model->joinTableData('product_storage',
  1165. 'product',
  1166. "a.storage_id = {$v['storage_id']} and product_id = {$v['pro_id']}",
  1167. 'a.product_id = b.id',
  1168. 'b.nameer, a.stock, a.advance_num'
  1169. );
  1170. if (!empty($pro)) {
  1171. $AvaStock = $pro['stock'] - $pro['advance_num'];
  1172. if ($v['pro_amount'] > $AvaStock) {
  1173. $data['status'] = 1;
  1174. $data['msg'] .= '商品‘' . $pro['nameer'] . '’库存不足,仅可售' . $AvaStock . '份。';
  1175. break;
  1176. }
  1177. } else {
  1178. $data['status'] = 1;
  1179. $data['msg'] .= '商品id:' . $v['pro_id'] . '可能删除或更改';
  1180. break;
  1181. }
  1182. }
  1183. }
  1184. return $data;
  1185. }
  1186. /**
  1187. * 获取门店场次
  1188. * @param $req
  1189. * @param $source 0前端 1后端
  1190. * @return false|\PDOStatement|string|\think\Collection
  1191. */
  1192. static function stoField($req, $source = 0)
  1193. {
  1194. $model = new StoreBoxModel();
  1195. //获取当前门店的场次
  1196. $where['shop_id'] = $req['sto_id'];
  1197. $where['status'] = 1;
  1198. $where['del_status'] = 1;
  1199. $filed = 'id, alias, genre, start, finish';
  1200. $list = $model->getList('set_bao_reserve', $where, $filed, 'genre asc');
  1201. $selDate = $req['date_select'];
  1202. $now = date('Y-m-d H:i:s');
  1203. //更改场次时段是否可选
  1204. foreach ($list as $k => $v) {
  1205. $sdStart = $selDate . ' ' . $v['start'];
  1206. $sdEnd = $selDate . ' ' . $v['finish'];
  1207. if ($sdEnd < $sdStart) {
  1208. $sdEnd = date('Y-m-d H:i:s', strtotime($sdEnd) + 86400);;
  1209. }
  1210. if($now >= $req['old_start_time'] && $now <= $req['old_end_time']){//开机内换房
  1211. //来自后端,未开机
  1212. if($source && $req['ord_status'] == 1){
  1213. $list[$k]['status'] = 1;
  1214. }else{
  1215. if($now >= $sdStart and $now <= $sdEnd){
  1216. $list[$k]['status'] = 1;
  1217. }else{
  1218. $list[$k]['status'] = 0;
  1219. }
  1220. }
  1221. }else if($now < $sdStart && $now < $req['old_start_time']){//未到欢唱时间换房
  1222. $list[$k]['status'] = 1;
  1223. }else{
  1224. if($source){//来源后端
  1225. $list[$k]['status'] = 1;
  1226. }else{
  1227. $list[$k]['status'] = 0;
  1228. }
  1229. }
  1230. }
  1231. return $list;
  1232. }
  1233. //获取满减达到金额
  1234. static function fullCutMoney($minusId)
  1235. {
  1236. $model = new StoreBoxModel();
  1237. //获取满减规则
  1238. $act = $model->getFind('act_content', "id = {$minusId}", 'include');
  1239. if (!empty($act['include'])) {
  1240. $actCont = explode('|', $act['include']);
  1241. return is_array($actCont) ? $actCont[0] : 0;
  1242. }
  1243. return null;
  1244. }
  1245. /**
  1246. * 获取换房价格
  1247. * @param $req
  1248. * @param null $order
  1249. * @param null $ordSource
  1250. * @param int $bActType @要更换套餐类型 1为虚拟套餐
  1251. * @return string
  1252. */
  1253. static function getExchangePrice($req, $order = null, $ordSource = null, $bActType = 0)
  1254. {
  1255. //这一步通常是前端换包调取应补差价
  1256. if (empty($order)) {
  1257. $now = date('Y-m-d H:i:s');
  1258. //获取原来订单信息
  1259. $model = new StoreBoxModel();
  1260. if (!empty($req['old_ord_id'])) {
  1261. $where = "id = '{$req['old_ord_id']}' and ord_status in ('1', '2') and end_time > '{$now}'";
  1262. } else {
  1263. $where = "ord_num = '{$req['old_ord_num']}' and ord_status in ('1', '2') and end_time > '{$now}'";
  1264. }
  1265. $order = $model->getFind('user_order', $where, 'ord_status, hours, start_time, end_time, act_id,
  1266. box_price, amount, full_cut, full_cut_amount'
  1267. );
  1268. }
  1269. if (empty($order)) {
  1270. $data['status'] = 0;
  1271. $data['msg'] = '已超时';
  1272. return json_encode($data);
  1273. }
  1274. //获取换房包厢或套餐价格
  1275. $chgOrder = Common::boxPricing($req['sto_id'], $req['new_box_type'], $req['sel_time_way'], $req['sel_act_id'], $req['new_sel_date']);
  1276. if (empty($chgOrder['up_price'])) {
  1277. $data['status'] = 0;
  1278. $data['msg'] = '未定义包厢价格';
  1279. return json_encode($data);
  1280. }
  1281. //添加开机后,套餐包不能换虚拟套餐
  1282. //if($order['act_id'] && $order['ord_status'] == 2 && $bActType){
  1283. // $data['status'] = 0;
  1284. // $data['msg'] = '开机后,套餐包不能换虚拟套餐包';
  1285. // return json_encode($data);
  1286. //}
  1287. $boxPrice = $order['box_price'];
  1288. $amount = $order['amount'];
  1289. $chgPrice = $ordSource == 3 ? $chgOrder['down_price'] : $chgOrder['up_price'];
  1290. $data['type'] = null;
  1291. //裸包换裸包
  1292. $lToL = empty($order['act_id']) && empty($req['sel_act_id']);
  1293. //套餐换套餐
  1294. $tToT = !empty($order['act_id']) && $req['sel_act_id'];
  1295. //裸包换套餐
  1296. $lToT = empty($order['act_id']) && $req['sel_act_id'];
  1297. //套餐换裸包
  1298. $tToL = !empty($order['act_id']) && empty($req['sel_act_id']);
  1299. //开机前
  1300. if ($order['ord_status'] == 1) {
  1301. if ($tToL) {
  1302. $data['status'] = 0;
  1303. $data['diff_price'] = self::ktvMoney(0);
  1304. $data['msg'] = '套餐包不能换裸包';
  1305. return json_encode($data);
  1306. } else if ($lToT && !empty($order['full_cut']) && !empty($order['full_cut_amount'])) {
  1307. $data['status'] = 0;
  1308. $data['diff_price'] = self::ktvMoney(0);
  1309. $data['msg'] = '已使用满减的裸包不能换套餐包';
  1310. return json_encode($data);
  1311. }else if ($lToL && !empty($order['full_cut_amount']) && empty($req['new_minus_id'])) {
  1312. $data['status'] = 0;
  1313. $data['diff_price'] = self::ktvMoney(0);
  1314. $data['msg'] = '已使用满减的包不能更换无满减的包';
  1315. return json_encode($data);
  1316. } else {
  1317. $data['status'] = 1;
  1318. $data['diff_price'] = self::ktvMoney(0);
  1319. $data['msg'] = '';
  1320. //1. 裸包换裸包、无使用满减、小包a换小包b
  1321. if ($lToL && empty($order['full_cut']) && $boxPrice == $chgPrice) {
  1322. } else if ($lToL && empty($order['full_cut']) && $boxPrice < $chgPrice) {
  1323. if (!empty($order['jiuzhe'])) {
  1324. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1325. } else {
  1326. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1327. }
  1328. } else if ($lToL && empty($order['full_cut']) && $boxPrice > $chgPrice) {
  1329. if (!empty($order['jiuzhe'])) {
  1330. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1331. } else {
  1332. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1333. }
  1334. //2. 裸包换裸包、有满减、已使用,小包a换小包b
  1335. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1336. && $boxPrice == $chgPrice) {
  1337. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1338. && $boxPrice < $chgPrice) {
  1339. //获取现在要达到的满减
  1340. // $nowFullMoney = Common::fullCutMoney($order['full_cut']);
  1341. //获取已买酒水金额
  1342. $usrWinMoney = Db::name('user_drinks_order')->where("box_id = {$req['box_id']} and start_time <= '{$req['new_start_time']}' and
  1343. end_time >= '{$req['new_start_time']}' and time_way = {$req['sel_time_way']} and
  1344. pay_state in (1, 2, 3)")->sum('amount');
  1345. //获取新包满减
  1346. $fullMoney = Common::fullCutMoney($req['new_minus_id']);
  1347. $difMoney = $fullMoney - $usrWinMoney;
  1348. if ($difMoney > 0) {
  1349. $difMoney = self::ktvMoney($difMoney);
  1350. $data['status'] = 0;
  1351. $data['diff_price'] = self::ktvMoney(0);
  1352. $data['msg'] = '您再购买酒水' . $difMoney . '元,才能达到满减条件';
  1353. return json_encode($data);
  1354. }else{
  1355. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1356. }
  1357. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1358. && $boxPrice > $chgPrice) {
  1359. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1360. //3. 裸包换裸包、有满减、未使用,小包a换小包b
  1361. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
  1362. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
  1363. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1364. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
  1365. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1366. //4. 套餐换套餐、小包套餐a换小包套餐b
  1367. } else if ($tToT && empty($order['full_cut']) && $amount == $chgPrice) {
  1368. //开机前,套餐换套餐,小换小
  1369. $data['type'] = 'qtt_xx';
  1370. } else if ($tToT && empty($order['full_cut']) && $amount < $chgPrice) {
  1371. if (!empty($order['jiuzhe'])) {
  1372. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1373. } else {
  1374. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1375. }
  1376. //开机前,套餐换套餐,小换大
  1377. $data['type'] = 'qtt_xd';
  1378. } else if ($tToT && empty($order['full_cut']) && $amount > $chgPrice) {
  1379. if (!empty($order['jiuzhe'])) {
  1380. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1381. } else {
  1382. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1383. }
  1384. //开机前,套餐换套餐,大换小
  1385. $data['type'] = 'qtt_dx';
  1386. //5. 无满减裸包换套餐包
  1387. } else if ($lToT && empty($order['full_cut']) && $boxPrice == $chgPrice) {
  1388. //开机前,裸包换套餐,小换小
  1389. $data['type'] = 'qlt_xx';
  1390. } else if ($lToT && empty($order['full_cut']) && $boxPrice < $chgPrice) {
  1391. if (!empty($order['jiuzhe'])) {
  1392. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1393. } else {
  1394. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1395. }
  1396. //开机前,裸包换套餐,小换大
  1397. $data['type'] = 'qlt_xd';
  1398. } else if ($lToT && empty($order['full_cut']) && $boxPrice > $chgPrice) {
  1399. if (!empty($order['jiuzhe'])) {
  1400. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1401. } else {
  1402. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1403. }
  1404. //开机前,裸包换套餐,大换小
  1405. $data['type'] = 'qlt_dx';
  1406. //6. 有满减,未使用裸包换套餐包
  1407. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
  1408. if (!empty($order['jiuzhe'])) {
  1409. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1410. } else {
  1411. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1412. }
  1413. //开机前,裸包换套餐,有满减,未使用,小换小
  1414. $data['type'] = 'qlt_yw_xx';
  1415. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
  1416. if (!empty($order['jiuzhe'])) {
  1417. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1418. } else {
  1419. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1420. }
  1421. //开机前,裸包换套餐,有满减,未使用,小换大
  1422. $data['type'] = 'qlt_yw_xd';
  1423. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
  1424. if (!empty($order['jiuzhe'])) {
  1425. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1426. } else {
  1427. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1428. }
  1429. //开机前,裸包换套餐,有满减,未使用,大换小
  1430. $data['type'] = 'qlt_yw_dx';
  1431. }
  1432. return json_encode($data);
  1433. }
  1434. } else if ($order['ord_status'] == 2) {//开机后
  1435. if ($tToL) {
  1436. $data['status'] = 0;
  1437. $data['diff_price'] = self::ktvMoney(0);
  1438. $data['msg'] = '套餐包不能换裸包';
  1439. return json_encode($data);
  1440. } else if ($lToT && !empty($order['full_cut']) && !empty($order['full_cut_amount'])) {
  1441. $data['status'] = 0;
  1442. $data['diff_price'] = self::ktvMoney(0);
  1443. $data['msg'] = '已使用满减的裸包不能更换套餐包';
  1444. return json_encode($data);
  1445. } else if ($lToL && !empty($order['full_cut_amount']) && empty($req['new_minus_id'])) {
  1446. $data['status'] = 0;
  1447. $data['diff_price'] = self::ktvMoney(0);
  1448. $data['msg'] = '已使用满减的包不能更换无满减的包';
  1449. return json_encode($data);
  1450. } else {
  1451. $data['status'] = 1;
  1452. $data['diff_price'] = self::ktvMoney(0);
  1453. $data['msg'] = '';
  1454. //1. 裸包换裸包、无满减、小包a换小包b
  1455. if ($lToL && empty($order['full_cut']) && $boxPrice == $chgPrice) {
  1456. } else if ($lToL && empty($order['full_cut']) && $boxPrice < $chgPrice) {
  1457. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1458. } else if ($lToL && empty($order['full_cut']) && $boxPrice > $chgPrice) {
  1459. $data['diff_price'] = 0;
  1460. $data['msg'] = '开机后,大包换小包不退差价';
  1461. //2. 裸包换裸包、有满减、已使用、小包a换小包b
  1462. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1463. && $boxPrice == $chgPrice) {
  1464. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1465. && $boxPrice < $chgPrice) {
  1466. //获取现在要达到的满减
  1467. // $nowFullMoney = Common::fullCutMoney($order['full_cut']);
  1468. //获取已买酒水金额
  1469. $usrWinMoney = Db::name('user_drinks_order')->where("box_id = {$req['box_id']} and start_time <= '{$req['new_start_time']}' and
  1470. end_time >= '{$req['new_start_time']}' and time_way = {$req['sel_time_way']} and
  1471. pay_state in (1, 2, 3)")->sum('amount');
  1472. //获取新包满减
  1473. $fullMoney = Common::fullCutMoney($req['new_minus_id']);
  1474. $difMoney = $fullMoney - $usrWinMoney;
  1475. if ($difMoney > 0) {
  1476. $difMoney = self::ktvMoney($difMoney);
  1477. $data['status'] = 0;
  1478. $data['diff_price'] = self::ktvMoney(0);
  1479. $data['msg'] = '您再购买酒水' . $difMoney . '元,才能达到满减条件';
  1480. return json_encode($data);
  1481. }else{
  1482. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1483. }
  1484. } else if ($lToL && !empty($order['full_cut']) && !empty($order['full_cut_amount']) && !empty($req['new_minus_id'])
  1485. && $boxPrice > $chgPrice) {
  1486. $data['msg'] = '开机后,使用满减的大包更换满减的小包,不退差价哦';
  1487. return json_encode($data);
  1488. //3. 裸包换裸包、有满减、未使用、小包a换小包b
  1489. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
  1490. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
  1491. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1492. } else if ($lToL && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
  1493. $data['msg'] = '开机后,有满减的大包更换有满减的小包,不退差价哦';
  1494. //4. 套餐换套餐、小包套餐a换小包套餐b
  1495. } else if ($tToT && $amount == $chgPrice) {
  1496. //开机后,套餐换套餐,小换小
  1497. $data['type'] = 'htt_xx';
  1498. } else if ($tToT && $amount < $chgPrice) {
  1499. if (!empty($order['jiuzhe'])) {
  1500. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1501. } else {
  1502. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1503. }
  1504. //开机后,套餐换套餐,小换大
  1505. $data['type'] = 'htt_xd';
  1506. } else if ($tToT && $amount > $chgPrice) {
  1507. $data['diff_price'] = self::ktvMoney(0);
  1508. $data['msg'] = '您订的套餐包不退差价哦,是否确认更换?';
  1509. //开机后,套餐换套餐,大换小
  1510. $data['type'] = 'htt_dx';
  1511. //5. 无满减裸包换套餐包
  1512. } else if ($lToT && empty($order['full_cut']) && $boxPrice == $chgPrice) {
  1513. //开机后,裸包换套餐,无满减,未使用,小换小
  1514. $data['type'] = 'hlt_ww_xx';
  1515. } else if ($lToT && empty($order['full_cut']) && $boxPrice < $chgPrice) {
  1516. if (!empty($order['jiuzhe'])) {
  1517. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1518. } else {
  1519. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1520. }
  1521. //开机后,裸包换套餐,无满减,未使用,小换大
  1522. $data['type'] = 'hlt_ww_xd';
  1523. } else if ($lToT && empty($order['full_cut']) && $boxPrice > $chgPrice) {
  1524. $data['diff_price'] = self::ktvMoney(0);
  1525. $data['msg'] = '您订的套餐包不退差价哦,是否确认更换?';
  1526. //开机后,裸包换套餐,无满减,未使用,大换小
  1527. $data['type'] = 'hlt_ww_dx';
  1528. //6. 未使用裸包换套餐包
  1529. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice == $chgPrice) {
  1530. //开机后,裸包换套餐,有满减,未使用,小换小
  1531. $data['type'] = 'hlt_yw_xx';
  1532. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice < $chgPrice) {
  1533. if (!empty($order['jiuzhe'])) {
  1534. $data['diff_price'] = self::ktvMoney(($chgPrice - $amount) * $order['jiuzhe']);
  1535. } else {
  1536. $data['diff_price'] = self::ktvMoney($chgPrice - $amount);
  1537. }
  1538. //开机后,裸包换套餐,有满减,未使用,小换大
  1539. $data['type'] = 'hlt_yw_xd';
  1540. } else if ($lToT && !empty($order['full_cut']) && empty($order['full_cut_amount']) && $boxPrice > $chgPrice) {
  1541. $data['diff_price'] = self::ktvMoney(0);
  1542. $data['msg'] = '您购买的裸包含有满减活动,换包不退差价,是否更换?';
  1543. //开机后,裸包换套餐,有满减,未使用,大换小
  1544. $data['type'] = 'hlt_yw_dx';
  1545. }
  1546. return json_encode($data);
  1547. }
  1548. }
  1549. //默认,无差价换包
  1550. $data['status'] = 1;
  1551. $data['diff_price'] = self::ktvMoney(0);
  1552. return json_encode($data);
  1553. }
  1554. //去掉千位分隔符
  1555. static function ktvMoney($price)
  1556. {
  1557. return number_format($price, 2, '.', '');
  1558. }
  1559. //获取订单付款方式
  1560. static function ktvPayWays($ord){
  1561. $payWay = [];
  1562. if(!empty($ord['huiyuanka']) && $ord['huiyuanka'] != '0.00'){
  1563. $payWay['huiyuanka'] = $ord['huiyuanka'];
  1564. }
  1565. if(!empty($ord['weixin']) && $ord['weixin'] != '0.00'){
  1566. $payWay['weixin'] = $ord['weixin'];
  1567. }
  1568. if(!empty($ord['zhifubao']) && $ord['zhifubao'] != '0.00'){
  1569. $payWay['zhifubao'] = $ord['zhifubao'];
  1570. }
  1571. if(!empty($ord['xianjin']) && $ord['xianjin'] != '0.00'){
  1572. $payWay['xianjin'] = $ord['xianjin'];
  1573. }
  1574. if(!empty($ord['yinlianka']) && $ord['yinlianka'] != '0.00'){
  1575. $payWay['yinlianka'] = $ord['yinlianka'];
  1576. }
  1577. if(!empty($ord['meituan']) && $ord['meituan'] != '0.00'){
  1578. $payWay['meituan'] = $ord['meituan'];
  1579. }
  1580. if(!empty($ord['jifenduihuan']) && $ord['jifenduihuan'] != '0.00'){
  1581. $payWay['jifenduihuan'] = $ord['jifenduihuan'];
  1582. }
  1583. if(!empty($ord['diyongjuan']) && $ord['diyongjuan'] != '0.00'){
  1584. $payWay['diyongjuan'] = $ord['diyongjuan'];
  1585. }
  1586. if(!empty($ord['moling']) && $ord['moling'] != '0.00'){
  1587. $payWay['moling'] = $ord['moling'];
  1588. }
  1589. if(!empty($ord['bazhe']) && $ord['bazhe'] != '0.00'){
  1590. $payWay['bazhe'] = $ord['bazhe'];
  1591. }
  1592. if(!empty($ord['youhui']) && $ord['youhui'] != '0.00'){
  1593. $payWay['youhui'] = $ord['youhui'];
  1594. }
  1595. if(!empty($ord['saoma']) && $ord['saoma'] != '0.00'){
  1596. $payWay['saoma'] = $ord['saoma'];
  1597. }
  1598. if(!empty($ord['hengcheng']) && $ord['hengcheng'] != '0.00'){
  1599. $payWay['hengcheng'] = $ord['hengcheng'];
  1600. }
  1601. if(!empty($ord['jiedai']) && $ord['jiedai'] != '0.00'){
  1602. $payWay['jiedai'] = $ord['jiedai'];
  1603. }
  1604. if(!empty($ord['yunPOS']) && $ord['yunPOS'] != '0.00'){
  1605. $payWay['yunPOS'] = $ord['yunPOS'];
  1606. }
  1607. if(!empty($ord['koubei']) && $ord['koubei'] != '0.00'){
  1608. $payWay['koubei'] = $ord['koubei'];
  1609. }
  1610. if(!empty($ord['dianzijuan']) && $ord['dianzijuan'] != '0.00'){
  1611. $payWay['dianzijuan'] = $ord['dianzijuan'];
  1612. }
  1613. if(!empty($ord['guazhang']) && $ord['guazhang'] != '0.00'){
  1614. $payWay['guazhang'] = $ord['guazhang'];
  1615. }
  1616. if(!empty($ord['qita']) && $ord['huiyuanka'] != '0.00'){
  1617. $payWay['qita'] = $ord['qita'];
  1618. }
  1619. if(!empty($ord['shoujiweixin']) && $ord['shoujiweixin'] != '0.00'){
  1620. $payWay['shoujiweixin'] = $ord['shoujiweixin'];
  1621. }
  1622. return $payWay;
  1623. }
  1624. /*
  1625. * 预购商品保存至文件
  1626. *
  1627. *
  1628. * $product_list = array(
  1629. * 0 => array(
  1630. * 'product_id' => '商品ID',
  1631. * 'num' => '预购数量',
  1632. * )
  1633. * )
  1634. * $model 表名
  1635. * $order_num 订单号
  1636. * $storage_id 仓库
  1637. * */
  1638. static function AddAdvance($model,$order_num,$storage_id,$product_list){
  1639. if(!empty($product_list)){
  1640. $logic = new \app\admins\logic\Purchase;
  1641. $product_ids = join(',',array_column($product_list,"product_id"));
  1642. $where = "storage_id = '{$storage_id}' and product_id in ($product_ids)";
  1643. $list = $logic->getListModel("product_storage", $where);
  1644. foreach($product_list as $k1=>$v1){
  1645. foreach($list as $k2=>$v2){
  1646. if($v1['product_id'] == $v2['product_id']){
  1647. $product_list[$k1]['stock'] = $v2['stock'];
  1648. $product_list[$k1]['advance_num'] = $v2['advance_num'];
  1649. }
  1650. }
  1651. }
  1652. $data = array(
  1653. 'model' => $model,
  1654. 'order_num' => $order_num,
  1655. 'add_time' => date('Y-m-d H:i:s'),
  1656. 'store_id' => Cookie::get('admin_control_store'),
  1657. 'storage_id' => $storage_id,
  1658. 'product_list'=> $product_list,
  1659. );
  1660. if(!file_exists('advance')){
  1661. mkdir ('advance',0777,true);
  1662. }
  1663. $str = json_encode($data);
  1664. $day = 'advance/'.date("Y-m-d");
  1665. file_put_contents($day, $str."^", FILE_APPEND);
  1666. }
  1667. }
  1668. //查询活动信息
  1669. static function actInfo($actid,$ordId){
  1670. $id = array();
  1671. $num = array();
  1672. $newInfos = array();
  1673. $where['id'] = $actid;
  1674. $logic = new \app\admins\logic\Activitycombo();
  1675. $ord = $logic->activityInfos('user_order', "id = {$ordId}", 'act_type', 'id desc', true);
  1676. if($ord['act_type'] == 2 || $ord['act_type'] == 6){
  1677. return true;
  1678. }
  1679. $info = $logic->activityInfos('act_content',$where,'act_type_id,bound_act_id','id desc',true);
  1680. if($info['act_type_id'] != 4){
  1681. return true;
  1682. }
  1683. //虚拟套餐查询绑定的商品套餐,获取商品套餐内容
  1684. $where['id'] = $info['bound_act_id'];
  1685. $re = $logic->activityInfos('act_content',$where,'include','id desc',true);
  1686. $res = explode('&', $re['include']);
  1687. foreach ($res as $kk => $vv) {
  1688. $ids = explode(';', $vv);
  1689. $id[] = explode('=', $ids[0])[1];
  1690. $num[] = explode('=', $ids[2])[1];
  1691. }
  1692. //查询商品信息
  1693. foreach ($id as $key => $val) {
  1694. $fields = 'id,nameer as name,price,pro_category as type,intro as goods_desc,pro_avatar as imgPath';
  1695. $gInfo = $logic->activityInfos('product', array('id'=>$val), $fields,'id desc',true);
  1696. $gInfo['num'] = $num[$key];
  1697. $gInfo['goods_source'] = 2;
  1698. $gInfo['act_id'] = $actid;
  1699. $newInfos[] = [
  1700. 'goods_id' => $gInfo['id'],
  1701. 'goods_name' => $gInfo['name'],
  1702. 'goods_price' => $gInfo['price'],
  1703. 'goods_num' => $gInfo['num'],
  1704. 'goods_type' => $gInfo['type'],
  1705. 'goods_img' => $gInfo['imgPath'],
  1706. 'goods_desc' => $gInfo['goods_desc'],
  1707. 'goods_source' => $gInfo['goods_source'],
  1708. 'act_id' => $actid,
  1709. 'sum_price' => $gInfo['price']*$gInfo['num'],
  1710. 'ord_id' => $ordId
  1711. ];
  1712. }
  1713. if(!empty($newInfos)){
  1714. $insert = Db::name('user_order_goods')->insertAll($newInfos);
  1715. if(!$insert){
  1716. return false;
  1717. }
  1718. }
  1719. return true;
  1720. }
  1721. //是否断电 返回true就是不可预定 false就是可以预定
  1722. public function interrupt($store_id,$start_time,$stop_time){
  1723. $logic = new \app\admins\logic\PubliclyOwned;
  1724. $info = $logic->getInfoModel("set_predetermine", "shop_id = $store_id and status = 1 and outage = 2");
  1725. if($info){
  1726. // echo $info['start_time'].'*'.$start_time.'<br>'.$info['stop_time'].'*'.$stop_time;
  1727. if( ($info['start_time']>=$start_time && $info['stop_time']<=$stop_time)
  1728. || ($info['start_time'] <= $start_time && $info['stop_time']>=$stop_time)
  1729. || ($info['stop_time']>=$start_time && $info['stop_time']<=$stop_time && $info['start_time']<=$start_time)
  1730. || ($info['stop_time']>=$start_time && $info['stop_time']>=$stop_time && $info['start_time']<=$stop_time)
  1731. ){
  1732. return array("msg"=>$info,"type"=>"error");
  1733. }
  1734. }
  1735. return array("type"=>"success");
  1736. }
  1737. //获取到期时间
  1738. static public function ExpiryTime($start, $end){
  1739. $expTime = null;
  1740. if($start < $end){
  1741. $df = date_diff(date_create($start), date_create($end));
  1742. if($df->y){
  1743. $expTime.=$df->y.'年';
  1744. }
  1745. if($df->m){
  1746. $expTime.=$df->m.'月';
  1747. }
  1748. if($df->d){
  1749. $expTime.=$df->d.'日';
  1750. }
  1751. if($df->h){
  1752. $expTime.=$df->h.'时';
  1753. }
  1754. if($df->i){
  1755. $expTime.=$df->i.'分';
  1756. }
  1757. if($df->s){
  1758. $expTime.=$df->s.'秒';
  1759. }
  1760. }else{
  1761. $expTime = '已到期';
  1762. }
  1763. return $expTime;
  1764. }
  1765. //卡卷核销
  1766. static public function AuthenticationCode($code){
  1767. $WxToken = new \app\wechat\service\WxToken;
  1768. $token = $WxToken->kev_getToken();
  1769. $url = "https://api.weixin.qq.com/card/code/consume?access_token=".$token;
  1770. $data = array(
  1771. "code" => $code
  1772. );
  1773. $result = $WxToken->https_request($url,json_encode($data));
  1774. return $result;
  1775. }
  1776. //获取短信发送
  1777. static public function send($tel, $send)
  1778. {
  1779. if (is_numeric($tel) && strlen($tel) == 11) {
  1780. $cc = '盛世欢唱提醒您:' . $send;
  1781. $zn = iconv("UTF-8", "GB2312//IGNORE", $cc);
  1782. $url = 'http://111.111.111.111:9050/cgi-bin/sendsms?username=sshc@sshc&password=******' . $tel . '&text=' . $zn . '&subid=&msgtype=4';
  1783. //$url = 'http://gateway.iems.net.cn/GsmsHttp?username=69833:admin&password=07914498&from=&to=' . $tel . '&content=' . $zn . '&presendTime=&expandPrefix=';
  1784. self::curl($url);
  1785. }
  1786. }
  1787. //万能curl
  1788. static public function curl($url, $data = null)
  1789. {
  1790. $ch = curl_init();
  1791. curl_setopt($ch, CURLOPT_URL, $url);
  1792. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1793. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1794. if (!empty($data)) {
  1795. curl_setopt($ch, CURLOPT_POST, 1);
  1796. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1797. }
  1798. $out = curl_exec($ch);
  1799. curl_close($ch);
  1800. return json_decode($out, true);
  1801. }
  1802. //得到相应会员卡等级积分
  1803. static public function GetGradeIntegral($grade_id=0){
  1804. $integral = 1;
  1805. if($grade_id > 0){
  1806. $logic = new \app\admins\logic\PubliclyOwned;
  1807. $info = $logic->getInfoModel("set_card_grade","id = $grade_id","integral");
  1808. $integral = $info['integral']?$info['integral']:$integral;
  1809. }
  1810. return $integral;
  1811. }
  1812. /**
  1813. * 发送卡卷
  1814. * store_id 门店ID
  1815. * send_type 发送类型 2充值 1消费
  1816. * price 充值/消费 金额
  1817. * user_id 用户ID
  1818. * type 得到卡卷类型 0 得到微信与铁壶卡卷 1 得到微信卡卷 2 得到铁壶卡卷
  1819. * **/
  1820. static public function SendingCoupon($store_id,$send_type,$price,$user_id,$type){
  1821. $logic = new \app\admins\logic\Coupon();
  1822. $coupon_list = $logic->getCouponList($send_type,$price,$store_id,$user_id,$type);
  1823. if($coupon_list){
  1824. $coupon_list = array_values($coupon_list);
  1825. $coupon_info = $coupon_list[0];
  1826. $data = array(
  1827. "user_id" => $user_id,
  1828. "add_time" => date('Y-m-d H:i'),
  1829. "coupon_id"=> $coupon_info['id'],
  1830. "code" => rand(10,99).time(),
  1831. "status" => 0,
  1832. );
  1833. if($coupon_info['time_type'] == 1){
  1834. $data['start_time'] = $coupon_info['start_time'];
  1835. $data['stop_time'] = $coupon_info['stop_time'];
  1836. }else{
  1837. $data['start_time'] = date('Y-m-d H:i');
  1838. $data['stop_time'] = date('Y-m-d H:i',time()+$coupon_info['day']*86400);
  1839. }
  1840. $result = $logic->AddModel("user_coupon", $data);
  1841. if($result){
  1842. $logic->UpdateModel("coupon", "id={$coupon_info['id']}", array('number'=>$coupon_info['number']-1));
  1843. return $result;
  1844. }
  1845. return false;
  1846. }else{
  1847. return false;
  1848. }
  1849. }
  1850. //获取管理员信息
  1851. static function GetAdmInfo($id, $fields){
  1852. $adm = new ModelUserAdmin();
  1853. return $adm->getFind('admin', "id = {$id}", $fields);
  1854. }
  1855. }