Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2019-03-26
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use think\Config;
  17. use app\admin\logic\ShopLogic;
  18. use app\admin\logic\ProductSpecLogic; // 用于产品规格逻辑功能处理
  19. use app\user\model\Pay as PayModel; //用于虚拟网盘商品付款后自动走流程处理
  20. class Shop extends Base {
  21. public $UsersConfigData = [];
  22. /**
  23. * 构造方法
  24. */
  25. public function __construct(){
  26. parent::__construct();
  27. $this->language_access(); // 多语言功能操作权限
  28. $this->users_db = Db::name('users'); // 会员信息表
  29. $this->shop_order_db = Db::name('shop_order'); // 订单主表
  30. $this->shop_order_details_db = Db::name('shop_order_details'); // 订单明细表
  31. $this->shop_address_db = Db::name('shop_address'); // 收货地址表
  32. $this->shop_express_db = Db::name('shop_express'); // 物流名字表
  33. $this->shop_order_log_db = Db::name('shop_order_log'); // 订单操作表
  34. $this->shipping_template_db = Db::name('shop_shipping_template'); // 运费模板表
  35. $this->product_spec_preset_db = Db::name('product_spec_preset'); // 产品规格预设表
  36. // 会员中心配置信息
  37. $this->UsersConfigData = getUsersConfigData('all');
  38. $this->assign('userConfig', $this->UsersConfigData);
  39. // 用于产品规格逻辑功能处理
  40. $this->ProductSpecLogic = new ProductSpecLogic;
  41. // 模型是否开启
  42. $channeltype_row = \think\Cache::get('extra_global_channeltype');
  43. $this->assign('channeltype_row', $channeltype_row);
  44. // 过期订单预处理
  45. $this->ShopLogic = new ShopLogic;
  46. $this->ShopLogic->OverdueOrderHandle();
  47. // 列出营销功能里已使用的模块
  48. $marketFunc = $this->ShopLogic->marketLogic();
  49. $this->assign('marketFunc', $marketFunc);
  50. // 获取核销插件数据
  51. $this->weappInfo = model('ShopPublicHandle')->getWeappVerifyInfo();
  52. $this->assign('weappInfo', $this->weappInfo);
  53. }
  54. public function home()
  55. {
  56. $url = url('Statistics/index', [], true, true);
  57. $url = preg_replace('/^http(s?)/i', $this->request->scheme(), $url);
  58. $this->redirect($url);
  59. exit;
  60. }
  61. /**
  62. * 商城设置
  63. */
  64. public function conf()
  65. {
  66. if (IS_POST) {
  67. $post = input('post.');
  68. if (!empty($post)) {
  69. $TestPass = $post['TestPass'];
  70. unset($post['TestPass']);
  71. if (0 == $TestPass) unset($post['shop']['shop_open_spec']);
  72. foreach ($post as $key => $val) {
  73. is_array($val) && getUsersConfigData($key, $val);
  74. }
  75. if (!empty($post['shop_open_comment']) && 1 === intval($post['shop_open_comment'])) {
  76. tpCache('web', ['web_shopcomment_switch' => 1]);
  77. } else if (isset($post['shop_open_comment']) && 0 === intval($post['shop_open_comment'])) {
  78. tpCache('web', ['web_shopcomment_switch' => 0]);
  79. }
  80. $this->success('设置成功!', url('Shop/conf'));
  81. }
  82. }
  83. $Result = VerifyLatestTemplate();
  84. if (!empty($Result)) getUsersConfigData('shop', ['shop_open_spec' => 0]);
  85. $TestPass = empty($Result) ? 1 : 0;
  86. $this->assign('TestPass', $TestPass);
  87. // 商城配置信息
  88. $smtp = tpCache('smtp');
  89. $this->assign('smtp', $smtp);
  90. return $this->fetch('conf');
  91. }
  92. /**
  93. * 订单列表
  94. */
  95. public function index()
  96. {
  97. // 是否安装 秒杀抢购插件
  98. $where = [
  99. 'status' => 1,
  100. 'code' => 'Seckill'
  101. ];
  102. $seckill = Db::name('weapp')->where($where)->count();
  103. $this->assign('seckill', $seckill);
  104. // 积分商城插件
  105. $pointsShop = model('ShopPublicHandle')->getWeappPointsShop();
  106. $this->assign('pointsShop', $pointsShop);
  107. // 手机端后台管理插件特定使用参数
  108. $isMobile = input('param.isMobile/d', 0);
  109. // 初始化数组和条件
  110. $where = [
  111. 'merchant_id' => 0,
  112. 'a.lang' => $this->admin_lang,
  113. ];
  114. // 订单号查询
  115. $order_code = input('order_code/s');
  116. if (!empty($order_code)) $where['a.order_code'] = ['LIKE', "%{$order_code}%"];
  117. // 支付方式查询
  118. $pay_name = input('pay_name/s');
  119. if (!empty($pay_name)) $where['a.pay_name'] = $pay_name;
  120. $this->assign('pay_name', $pay_name);
  121. // 订单下单终端查询
  122. $order_terminal = input('order_terminal/d');
  123. if (!empty($order_terminal)) $where['a.order_terminal'] = $order_terminal;
  124. $this->assign('order_terminal', $order_terminal);
  125. // 商品类型查询
  126. $contains_virtual = input('contains_virtual/d');
  127. if (!empty($contains_virtual)) $where['a.contains_virtual'] = $contains_virtual;
  128. $this->assign('contains_virtual', $contains_virtual);
  129. //活动订单查询
  130. $act_type = input('act_type/d', 0);
  131. // 普通订单
  132. if (1 === intval($act_type)) {
  133. if (!empty($seckill)) $where['a.is_seckill_order'] = 0;
  134. if (!empty($pointsShop)) $where['a.points_shop_order'] = 0;
  135. }
  136. // 秒杀插件订单
  137. else if (2 === intval($act_type) && !empty($seckill)) {
  138. $where['a.is_seckill_order'] = ['gt', 0];
  139. }
  140. // 积分商城插件订单
  141. else if (3 === intval($act_type) && !empty($pointsShop)) {
  142. $where['a.points_shop_order'] = 1;
  143. }
  144. //时间检索条件
  145. $begin = strtotime(input('param.add_time_begin/s'));
  146. $end = input('param.add_time_end/s');
  147. !empty($end) && $end .= ' 23:59:59';
  148. $end = strtotime($end);
  149. // 时间检索
  150. if ($begin > 0 && $end > 0) {
  151. $where['a.add_time'] = array('between', "$begin, $end");
  152. } else if ($begin > 0) {
  153. $where['a.add_time'] = array('egt', $begin);
  154. } else if ($end > 0) {
  155. $where['a.add_time'] = array('elt', $end);
  156. }
  157. // 订单状态查询
  158. $order_status = input('order_status/s');
  159. if (!empty($order_status)) $where['a.order_status'] = (10 == $order_status) ? 0 : $order_status;
  160. // 分页查询
  161. $count = $this->shop_order_db->alias('a')->where($where)->count('order_id');
  162. $pageObj = new Page($count, config('paginate.list_rows'));
  163. // 订单主表数据查询
  164. $list = $this->shop_order_db->alias('a')
  165. ->field('a.*, b.username as u_username, b.nickname as u_nickname, b.mobile as u_mobile')
  166. ->where($where)
  167. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  168. ->order('a.order_id desc')
  169. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  170. ->select();
  171. if (empty($list) && !empty($order_code)) {
  172. // 通过商品名称查询订单号
  173. $where_1['product_name'] = ['LIKE', "%{$order_code}%"];
  174. $order_ids = $this->shop_order_details_db->where($where_1)->group('order_id')->column('order_id');
  175. // 重新查询订单主表
  176. unset($where['a.order_code']);
  177. $where['a.order_id'] = ['IN', $order_ids];
  178. // 分页查询
  179. $count = $this->shop_order_db->alias('a')->where($where)->count('order_id');
  180. $pageObj = new Page($count, config('paginate.list_rows'));
  181. // 订单主表数据查询
  182. $list = $this->shop_order_db->alias('a')
  183. ->field('a.*, b.username as u_username, b.nickname as u_nickname, b.mobile as u_mobile')
  184. ->where($where)
  185. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  186. ->order('a.order_id desc')
  187. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  188. ->select();
  189. }
  190. $order_ids = [];
  191. $OrderReminderID = [];
  192. foreach ($list as $key => $value) {
  193. array_push($order_ids, $value['order_id']);
  194. if (1 == $value['order_status']) array_push($OrderReminderID, $value['order_id']);
  195. }
  196. // 处理订单详情数据
  197. $where = [
  198. 'a.order_id' => ['IN', $order_ids]
  199. ];
  200. $DetailsData = $this->shop_order_details_db->alias('a')
  201. ->field('a.*, b.service_id, b.status')
  202. ->where($where)
  203. ->join('__SHOP_ORDER_SERVICE__ b', 'a.details_id = b.details_id && b.status NOT IN (3, 8, 9)', 'LEFT')
  204. ->order('details_id asc')
  205. ->select();
  206. $ArchivesData = get_archives_data($DetailsData, 'product_id');
  207. $OrderServiceStatus = Config::get('global.order_service_status');
  208. foreach ($DetailsData as $key => $value) {
  209. // 售后信息处理
  210. $value['service_id'] = !empty($value['service_id']) ? $value['service_id'] : 0;
  211. $value['status'] = !empty($value['status']) ? $value['status'] : 0;
  212. $value['status_name'] = !empty($value['status']) ? $OrderServiceStatus[$value['status']] : '';
  213. // 产品属性处理
  214. $value['data'] = !empty($value['data']) ? unserialize($value['data']) : [];
  215. $value['pointsGoodsBuyField'] = !empty($value['data']['pointsGoodsBuyField']) ? json_decode($value['data']['pointsGoodsBuyField'], true) : [];
  216. $value['data'] = htmlspecialchars_decode(htmlspecialchars_decode($value['data']['spec_value']));
  217. // 组合数据
  218. $value['data'] = explode('<br/>', $value['data']);
  219. $valueData = '';
  220. foreach ($value['data'] as $key_1 => $value_1) {
  221. $delimiter = '';//!empty($isMobile) ? ';' : '';
  222. if (!empty($value_1)) $valueData .= '<span>' . trim(strrchr($value_1, ':'),':') . '</span>' . $delimiter;
  223. }
  224. $value['data'] = $valueData;
  225. $value['arcurl'] = get_arcurl($ArchivesData[$value['product_id']]);
  226. $value['litpic'] = handle_subdir_pic(get_default_pic($value['litpic']));
  227. $DetailsData[$key] = $value;
  228. }
  229. // 把订单详情数据植入订单数据
  230. $defaultDetails = [
  231. 'details_id' => 0,
  232. 'order_id' => 0,
  233. 'users_id' => 0,
  234. 'product_id' => 0,
  235. 'product_name' => '',
  236. 'num' => 0,
  237. 'data' => '',
  238. 'product_price' => 0,
  239. 'prom_type' => 0,
  240. 'litpic' => get_default_pic(),
  241. 'apply_service' => 0,
  242. 'is_comment' => 0,
  243. 'lang' => 'cn',
  244. 'add_time' => 0,
  245. 'update_time' => 0,
  246. 'service_id' => 0,
  247. 'status' => 0,
  248. 'status_name' => '',
  249. 'arcurl' => '',
  250. ];
  251. // 把订单详情数据植入订单数据
  252. $DetailsDataGroup = group_same_key($DetailsData, 'order_id');
  253. foreach ($list as $key => $value) {
  254. // 处理会员昵称
  255. $value['u_nickname'] = !empty($value['u_nickname']) ? $value['u_nickname'] : $value['u_username'];
  256. // 处理订单详情数据
  257. $value['Details'] = $DetailsDataGroup[$value['order_id']];
  258. if (empty($value['Details'])) $value['Details'] = [$defaultDetails];
  259. // 商品条数
  260. $value['rowspan'] = count($value['Details']);
  261. // 添加时间
  262. $value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
  263. // 更新时间
  264. $value['update_time'] = date('Y-m-d H:i:s', $value['update_time']);
  265. // 重新赋值数据
  266. $list[$key] = $value;
  267. }
  268. // 存在积分商城订单则执行
  269. $pointsShopOrder = !empty($list) ? get_arr_column($list, 'points_shop_order') : [];
  270. if (!empty($pointsShopOrder) && in_array(1, $pointsShopOrder)) {
  271. $weappInfo = model('ShopPublicHandle')->getWeappPointsShop();
  272. if (!empty($weappInfo)) {
  273. $pointsShopLogic = new \weapp\PointsShop\logic\PointsShopLogic();
  274. $list = $pointsShopLogic->pointsShopOrderDataHandle($list);
  275. }
  276. }
  277. // 查询订单被提醒发货次数
  278. if (!empty($OrderReminderID)) {
  279. $field = 'order_id, count(action_id) as action_count';
  280. $group = 'order_id';
  281. $LogWhere = [
  282. 'action_desc' => '提醒成功!',
  283. 'order_id' => ['IN', $OrderReminderID]
  284. ];
  285. $LogData = $this->shop_order_log_db->field($field)->group($group)->where($LogWhere)->getAllWithIndex('order_id');
  286. }
  287. // // 计算单页总额
  288. // $total_money = $this->shop_order_db->alias('a')->where($where)->where('order_id','IN',$order_ids)->value("SUM(`order_amount`) as `total_money`");
  289. // /*查询已退还的总额*/
  290. // $list_order_id = get_arr_column($list, 'order_id');
  291. // $where_new = [
  292. // 'service_type' => 2,
  293. // 'status' => ['IN', [2, 4, 5, 7]],
  294. // 'order_id' => ['IN', $list_order_id]
  295. // ];
  296. // $refund_balance = Db::name('shop_order_service')->where($where_new)->value("SUM(`refund_balance`) as `refund_balance`");
  297. // /* END */
  298. // // 计算单页总额 - 已退还的总额
  299. // if (!empty($refund_balance)) $total_money = $total_money - $refund_balance;
  300. // $this->assign('total_money', $total_money);
  301. // 分页显示输出
  302. $pageStr = $pageObj->show();
  303. // 获取订单方式名称
  304. $pay_method_arr = Config::get('global.pay_method_arr');
  305. // 获取订单状态
  306. $admin_order_status_arr = Config::get('global.admin_order_status_arr');
  307. // 数据加载
  308. $this->assign('list', $list);
  309. $this->assign('page', $pageStr);
  310. $this->assign('pager', $pageObj);
  311. $this->assign('LogData', $LogData);
  312. $this->assign('pay_method_arr', $pay_method_arr);
  313. $this->assign('admin_order_status_arr', $admin_order_status_arr);
  314. // 是否开启文章付费
  315. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  316. foreach ($channelRow as &$val){
  317. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  318. }
  319. $this->assign('channelRow', $channelRow);
  320. // 是否开启货到付款
  321. $shopOpenOffline = 1;
  322. if (0 === intval($this->UsersConfigData['shop_open_offline']) || !isset($this->UsersConfigData['shop_open_offline'])) {
  323. $shopOpenOffline = 0;
  324. }
  325. $this->assign('shopOpenOffline', $shopOpenOffline);
  326. // 开启的商城商品类型
  327. $shopType = $this->UsersConfigData['shop_type'];
  328. $this->assign('shopType', $shopType);
  329. // 是否开启微信、支付宝支付
  330. $where = [
  331. 'status' => 1,
  332. 'pay_mark' => ['IN', ['wechat', 'alipay']]
  333. ];
  334. $payApiConfig = Db::name('pay_api_config')->where($where)->select();
  335. $openWeChat = $openAliPay = 1;
  336. foreach ($payApiConfig as $key => $value) {
  337. $payInfo = unserialize($value['pay_info']);
  338. if (!empty($payInfo) && isset($payInfo['is_open_wechat']) && 0 === intval($payInfo['is_open_wechat'])) {
  339. $openWeChat = 0;
  340. }
  341. if (!empty($payInfo) && isset($payInfo['is_open_alipay']) && 0 === intval($payInfo['is_open_alipay'])) {
  342. $openAliPay = 0;
  343. }
  344. }
  345. $this->assign('openWeChat', $openWeChat);
  346. $this->assign('openAliPay', $openAliPay);
  347. // 是否安装 可视化微信小程序(商城版),未安装开启则不显示小程序支付
  348. $where = [
  349. 'status' => 1,
  350. 'code' => 'DiyminiproMall'
  351. ];
  352. $openMall = Db::name('weapp')->where($where)->count();
  353. $this->assign('openMall', $openMall);
  354. // 如果安装手机端后台管理插件并且在手机端访问时执行
  355. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  356. $mbPage = input('param.p/d', 1);
  357. $nullShow = intval($pageObj->totalPages) === intval($mbPage) ? 1 : 0;
  358. $this->assign('nullShow', $nullShow);
  359. if ($mbPage >= 2) {
  360. return $this->display('shop/order_list');
  361. } else {
  362. return $this->display('shop/index');
  363. }
  364. } else {
  365. return $this->fetch();
  366. }
  367. }
  368. /**
  369. * 订单详情
  370. */
  371. public function order_details()
  372. {
  373. $order_id = input('param.order_id/d');
  374. if (!empty($order_id)) {
  375. // 查询订单信息
  376. $this->GetOrderData($order_id);
  377. // 查询订单操作记录
  378. $Action = $this->shop_order_log_db->where('order_id',$order_id)->order('action_id desc')->select();
  379. // 操作记录数据处理
  380. foreach ($Action as $key => $value) {
  381. $value['action_note'] = str_replace('!', '', $value['action_note']);
  382. $value['action_note'] = str_replace('!', '', $value['action_note']);
  383. // 会员操作
  384. if (!empty($value['users_id'])) {
  385. $Action[$key]['action_note'] = '[买家] ' . $value['action_note'];
  386. $user = $this->users_db->field('username, nickname')->where('users_id', $value['users_id'])->find();
  387. $Action[$key]['action_users'] = !empty($user['nickname']) ? $user['nickname'] : $user['username'];
  388. }
  389. // 管理员操作
  390. else if (!empty($value['action_user'])) {
  391. $Action[$key]['action_note'] = '[商家] ' . $value['action_note'];
  392. $user_name = Db::name('admin')->where('admin_id', $value['action_user'])->getField('user_name');
  393. $Action[$key]['action_users'] = !empty($user_name) ? $user_name : '';
  394. }
  395. // 系统操作
  396. else {
  397. $Action[$key]['action_note'] = '[系统] ' . $value['action_note'];
  398. $Action[$key]['action_users'] = '自动操作';
  399. }
  400. $Action[$key]['action_desc'] = str_replace("!", "", $value['action_desc']);
  401. // 操作时,订单发货状态
  402. $Action[$key]['express_status'] = 1 == $value['express_status'] ? '已发货' : '未发货';
  403. // 操作时,订单付款状态
  404. $Action[$key]['pay_status'] = 1 == $value['pay_status'] ? '已支付' : '未支付';
  405. }
  406. $this->assign('Action', $Action);
  407. // 如果安装手机端后台管理插件并且在手机端访问时执行
  408. $isMobile = input('param.isMobile/d', 0);
  409. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  410. return $this->display('shop/order_details');
  411. } else {
  412. return $this->fetch('order_details');
  413. }
  414. }else{
  415. $this->error('非法访问!');
  416. }
  417. }
  418. // 订单备注
  419. public function order_remarks()
  420. {
  421. if (IS_AJAX_POST) {
  422. $post = input('post.');
  423. if (!empty($post['order_id']) && !empty($post['order_remarks'])) {
  424. $admin_id = session('admin_info.admin_id');
  425. $admin_info = Db::name('admin')->where(['admin_id'=>$admin_id])->find();
  426. // 执行条件
  427. $where = [
  428. 'order_id' => intval($post['order_id'])
  429. ];
  430. // 查询订单备注信息
  431. $adminNote = Db::name('shop_order')->where($where)->getField('admin_note');
  432. if (empty($adminNote)) {
  433. $adminNote = [
  434. 'times' => date('Y-m-d H:i:s'),
  435. 'admin_id' => $admin_info['admin_id'],
  436. 'admin_name' => $admin_info['user_name'],
  437. 'remarks' => strval($post['order_remarks'])
  438. ];
  439. $update = [
  440. 'admin_note' => serialize([$adminNote]),
  441. 'update_time' => getTime()
  442. ];
  443. } else {
  444. // 解析原先的备注信息
  445. $adminNote = unserialize($adminNote);
  446. // 新的备注信息
  447. $adminNoteNew = [
  448. 'times' => date('Y-m-d H:i:s'),
  449. 'admin_id' => $admin_info['admin_id'],
  450. 'admin_name' => $admin_info['user_name'],
  451. 'remarks' => strval($post['order_remarks'])
  452. ];
  453. // 合并两个备注信息
  454. $adminNote = array_merge($adminNote, [$adminNoteNew]);
  455. $update = [
  456. 'admin_note' => serialize($adminNote),
  457. 'update_time' => getTime()
  458. ];
  459. }
  460. if (!empty($update)) $updateID = Db::name('shop_order')->where($where)->update($update);
  461. if (!empty($updateID)) $this->success('备注成功');
  462. }
  463. $this->error('操作失败,刷新重试!');
  464. }
  465. $order_id = input('param.order_id/d', 0);
  466. $this->assign('order_id', $order_id);
  467. $where = [
  468. 'order_id' => intval($order_id)
  469. ];
  470. $remarksList = Db::name('shop_order')->where($where)->getField('admin_note');
  471. $remarksList = !empty($remarksList) ? unserialize($remarksList) : [];
  472. krsort($remarksList);
  473. $this->assign('remarksList', $remarksList);
  474. return $this->fetch();
  475. }
  476. /**
  477. * 订单发货
  478. */
  479. public function order_send()
  480. {
  481. $order_id = input('param.order_id');
  482. if ($order_id) {
  483. // 查询订单信息
  484. $this->GetOrderData($order_id);
  485. $where = [
  486. 'is_choose' => 1,
  487. ];
  488. $express = $this->shop_express_db->where($where)->order('sort_order asc, express_id asc')->select();
  489. $this->assign('express', $express);
  490. // 如果安装手机端后台管理插件并且在手机端访问时执行
  491. $isMobile = input('param.isMobile/d', 0);
  492. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  493. return $this->display('shop/order_send');
  494. } else {
  495. return $this->fetch('order_send');
  496. }
  497. }
  498. }
  499. /**
  500. * 订单发货操作
  501. */
  502. public function order_send_operating()
  503. {
  504. if (IS_POST) {
  505. $post = input('post.');
  506. // 参数强制转类型
  507. $post['order_id'] = intval($post['order_id']);
  508. $post['users_id'] = intval($post['users_id']);
  509. $post['prom_type'] = intval($post['prom_type']);
  510. $post['express_id'] = intval($post['express_id']);
  511. // 需要物流时必须选择快递
  512. if (isset($post['prom_type']) && 0 === $post['prom_type']) {
  513. if (empty($post['express_id']) || empty($post['express_name']) || empty($post['express_code'])) {
  514. $this->error('请选择快递公司');
  515. }
  516. }
  517. // 条件数组
  518. $Where = [
  519. 'order_id' => $post['order_id'],
  520. 'users_id' => $post['users_id'],
  521. 'lang' => $this->admin_lang,
  522. ];
  523. // 更新数组
  524. $UpdateData = [
  525. 'order_status' => 2,
  526. 'express_order' => $post['express_order'],
  527. 'express_name' => $post['express_name'],
  528. 'express_code' => $post['express_code'],
  529. 'express_time' => getTime(),
  530. 'consignee' => $post['consignee'],
  531. 'update_time' => getTime(),
  532. 'virtual_delivery' => $post['virtual_delivery'],
  533. ];
  534. // 订单操作记录逻辑
  535. $LogWhere = [
  536. 'order_id' => $post['order_id'],
  537. 'express_status' => 1,
  538. ];
  539. $LogData = $this->shop_order_log_db->where($LogWhere)->count();
  540. if (!empty($LogData)) {
  541. // 数据存在则表示为修改发货内容
  542. $OrderData = $this->shop_order_db->where($Where)->field('prom_type')->find();
  543. $Desc = '修改发货内容!';
  544. if (1 == $post['prom_type']) {
  545. // 提交的数据为虚拟订单
  546. if ($OrderData['prom_type'] != $post['prom_type']) {
  547. // 此处判断后,提交的订单类型和数据库中的订单类型不相同,表示普通订单修改为虚拟订单
  548. $Note = '管理员将普通订单修改为虚拟订单!';
  549. if (!empty($post['virtual_delivery'])) {
  550. // 若存在数据则拼装
  551. $Note .= '给买家回复:'.$post['virtual_delivery'];
  552. }
  553. } else {
  554. // 继续保持为虚拟订单修改
  555. $Note = '虚拟订单,无需物流。';
  556. if (!empty($post['virtual_delivery'])) {
  557. // 若存在数据则拼装
  558. $Note .= '给买家回复:'.$post['virtual_delivery'];
  559. }
  560. }
  561. } else {
  562. // 提交的数据为普通订单
  563. if ($OrderData['prom_type'] != $post['prom_type']) {
  564. // 这一段暂时无用,因为发货时,暂时无法选择将虚拟订单修改为普通订单
  565. $Note = '管理员将虚拟订单修改为普通订单!';
  566. if (!empty($post['virtual_delivery'])) {
  567. // 若存在数据则拼装
  568. $Note .= '给买家回复:'.$post['virtual_delivery'];
  569. }
  570. } else {
  571. // 继续保持为普通订单修改
  572. $Note = '使用'.$post['express_name'].'发货成功!';
  573. }
  574. }
  575. $UpdateData['prom_type'] = $post['prom_type'];
  576. } else {
  577. // 数据不存在则表示为初次发货,拼装发货内容
  578. $Desc = '发货成功!';
  579. $Note = '使用'.$post['express_name'].'发货成功!';
  580. if ('1' == $post['prom_type']) {
  581. // 若为虚拟订单,无需发货物流。
  582. $UpdateData['prom_type'] = $post['prom_type'];
  583. $Note = '虚拟订单,无需物流。';
  584. if (!empty($post['virtual_delivery'])) {
  585. // 若存在数据则拼装
  586. $Note .= '给买家回复:'.$post['virtual_delivery'];
  587. }
  588. }
  589. }
  590. // 配送单号
  591. if (empty($post['prom_type']) && empty($post['express_order'])) $this->error('配送单号不能为空');
  592. // 更新订单主表信息
  593. $IsOrder = $this->shop_order_db->where($Where)->update($UpdateData);
  594. if (!empty($IsOrder)) {
  595. // 更新订单明细表信息
  596. $Data['update_time'] = getTime();
  597. $this->shop_order_details_db->where('order_id', $post['order_id'])->update($Data);
  598. // 添加订单操作记录
  599. AddOrderAction($post['order_id'], 0, session('admin_id'), 2, 1, 1, $Desc, $Note);
  600. // 查询会员信息
  601. $Field = 'username, nickname, email, mobile';
  602. $Users = $this->users_db->field($Field)->where('users_id', $post['users_id'])->find();
  603. // 邮箱发送
  604. $SmtpConfig = tpCache('smtp');
  605. $Result['email'] = GetEamilSendData($SmtpConfig, $Users, $post, 2);
  606. // 手机发送
  607. $SmsConfig = tpCache('sms');
  608. $Result['mobile'] = GetMobileSendData($SmsConfig, $Users, $post, 2);
  609. // 发送站内信给会员
  610. $NickName = !empty($Users['nickname']) ? $Users['nickname'] : $Users['username'];
  611. SendNotifyMessage($UpdateData, 6, 0, $post['users_id'], $NickName);
  612. $this->success('发货成功', null, $Result);
  613. } else {
  614. $this->error('发货失败');
  615. }
  616. }
  617. }
  618. // 订单更新收货地址
  619. public function order_address()
  620. {
  621. if (IS_AJAX_POST) {
  622. $post = input('post.');
  623. // 判断数据
  624. if (empty($post['consignee'])) $this->error('请填写收货人姓名!');
  625. if (empty($post['mobile'])) $this->error('请填写收货人手机!');
  626. if (empty($post['province'])) $this->error('请选择省份!');
  627. if (empty($post['city'])) $this->error('请选择城市!');
  628. if (empty($post['district'])) $this->error('请选择县区!');
  629. if (empty($post['address'])) $this->error('请填写详细地址!');
  630. // 更新地址
  631. $where = [
  632. 'order_id' => intval($post['order_id']),
  633. ];
  634. $update = [
  635. 'consignee' => strval($post['consignee']),
  636. 'mobile' => strval($post['mobile']),
  637. 'province' => intval($post['province']),
  638. 'city' => intval($post['city']),
  639. 'district' => intval($post['district']),
  640. 'address' => strval($post['address']),
  641. 'update_time' => getTime()
  642. ];
  643. $updateID = Db::name('shop_order')->where($where)->update($update);
  644. if (!empty($updateID)) {
  645. // 添加订单操作记录
  646. AddOrderAction($post['order_id'], 0, session('admin_id'), 1, 0, 1, '修改地址!', '修改买家订单收货信息!');
  647. $this->success('更新成功');
  648. } else {
  649. $this->error('操作失败,刷新重试!');
  650. }
  651. }
  652. $order_id = input('param.order_id/d', 0);
  653. $this->assign('order_id', $order_id);
  654. $address = Db::name('shop_order')->field('consignee, mobile, province, city, district, address')->where($where)->find($order_id);
  655. $this->assign('address', $address);
  656. $provinceList = get_province_list();
  657. $this->assign('provinceList', $provinceList);
  658. $cityList = Db::name('region')->where('parent_id', $address['province'])->select();
  659. $this->assign('cityList', $cityList);
  660. $areaList = Db::name('region')->where('parent_id', $address['city'])->select();
  661. $this->assign('areaList', $areaList);
  662. return $this->fetch();
  663. }
  664. // 联动地址获取
  665. public function ajaxGetSpecifyRegion()
  666. {
  667. $parent_id = input('param.parent_id/d');
  668. $region = Db::name('region')->where("parent_id", $parent_id)->select();
  669. $html = '';
  670. if (!empty($region)) {
  671. // 拼装下拉选项
  672. foreach ($region as $value) {
  673. $html .= "<option value='{$value['id']}'>{$value['name']}</option>";
  674. }
  675. }
  676. $this->success('查询成功!', null, $html);
  677. }
  678. /**
  679. * 查询快递名字及Code
  680. */
  681. public function order_express()
  682. {
  683. // 查询条件
  684. $where = [];
  685. $keywords = input('keywords/s');
  686. if (!empty($keywords)) $where['express_name'] = ['LIKE', "%{$keywords}%"];
  687. // 分页查询
  688. $count = $this->shop_express_db->where($where)->count('express_id');
  689. $pageObj = new Page($count, 10);
  690. // 查询数据
  691. $ExpressData = $this->shop_express_db->where($where)
  692. ->order('sort_order asc,express_id asc')
  693. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  694. ->select();
  695. // 计算选中个数
  696. $where['is_choose'] = 1;
  697. $selectNum = $this->shop_express_db->where($where)->count();
  698. $this->assign('selectNum', $selectNum);
  699. // 加载模板
  700. $pageStr = $pageObj->show();
  701. $select = input('param.select/d', 0);
  702. $this->assign('select', $select);
  703. $this->assign('pageStr', $pageStr);
  704. $this->assign('pageObj', $pageObj);
  705. $this->assign('ExpressData', $ExpressData);
  706. return $this->fetch('order_express');
  707. }
  708. // 全部选中/全部取消
  709. public function express_is_choose()
  710. {
  711. if (IS_AJAX_POST) {
  712. $is_choose = input('post.is_choose/d', 0);
  713. if (isset($is_choose) && $is_choose >= 0) {
  714. $where = [
  715. 'is_choose' => !empty($is_choose) ? 0 : 1
  716. ];
  717. $update = [
  718. 'is_choose' => $is_choose,
  719. 'update_time' => getTime(),
  720. ];
  721. $ResultID = $this->shop_express_db->where($where)->update($update);
  722. if (!empty($ResultID)) $this->success('操作成功');
  723. }
  724. }
  725. $this->error('操作失败');
  726. }
  727. /**
  728. * 管理员后台标记订单状态
  729. */
  730. public function order_mark_status()
  731. {
  732. if (IS_POST) {
  733. $post = input('post.');
  734. // 条件数组
  735. $Where = [
  736. 'order_id' => $post['order_id'],
  737. 'users_id' => $post['users_id'],
  738. 'lang' => $this->admin_lang,
  739. ];
  740. if ('ddsc' == $post['status_name']) {
  741. // 订单删除
  742. $IsDelete = $this->shop_order_db->where($Where)->delete();
  743. if (!empty($IsDelete)) {
  744. $Where = [
  745. 'order_id' => $post['order_id'],
  746. ];
  747. // 同步删除订单下的操作记录
  748. $this->shop_order_log_db->where($Where)->delete();
  749. // 同步删除订单下的产品
  750. $this->shop_order_details_db->where($Where)->delete();
  751. $this->success('删除成功!', url('Shop/index'));
  752. }else{
  753. $this->error('数据错误!');
  754. }
  755. }else{
  756. $OrderData = $this->shop_order_db->where($Where)->find();
  757. // 更新数组
  758. $UpdateData = [
  759. 'update_time' => getTime(),
  760. ];
  761. // 根据不同操作标记不同操作内容
  762. if ('yfk' == $post['status_name']) {
  763. // 订单标记为付款,追加更新数组
  764. $UpdateData['order_status'] = '1';
  765. $UpdateData['pay_time'] = getTime();
  766. // 管理员付款
  767. $UpdateData['pay_name'] = 'admin_pay';
  768. $UpdateData['wechat_pay_type'] = '';
  769. /*用于添加订单操作记录*/
  770. $order_status = '1'; // 订单状态
  771. $express_status = '0'; // 发货状态
  772. $pay_status = '1'; // 支付状态
  773. $action_desc = '付款成功!'; // 操作明细
  774. $action_note = '管理员确认订单付款!'; // 操作备注
  775. /*结束*/
  776. }else if ('ysh' == $post['status_name']) {
  777. // 如果后台【商城中心】-【商城配置】-【订单设置】-收货后可维权时间设置为0,则表示订单不允许申请维权
  778. $OrderData['allow_service'] = !empty($this->UsersConfigData['order_right_protect_time']) ? 0 : 1;
  779. // 订单确认收货,追加更新数组
  780. $UpdateData['order_status'] = '3';
  781. $UpdateData['confirm_time'] = getTime();
  782. /*用于添加订单操作记录*/
  783. $order_status = '3'; // 订单状态
  784. $express_status = '1'; // 发货状态
  785. $pay_status = '1'; // 支付状态
  786. $action_desc = '确认收货!'; // 操作明细
  787. $action_note = '管理员确认订单已收货!'; // 操作备注
  788. /*结束*/
  789. }else if ('gbdd' == $post['status_name']) {
  790. // 订单关闭,追加更新数组
  791. $UpdateData['order_status'] = '-1';
  792. /*用于添加订单操作记录*/
  793. $order_status = '-1'; // 订单状态
  794. if ('0' == $OrderData['order_status'] || '1' == $OrderData['order_status']) {
  795. $express_status = '0'; // 发货状态
  796. $pay_status = '0'; // 支付状态
  797. }else{
  798. $express_status = '1'; // 发货状态
  799. $pay_status = '1'; // 支付状态
  800. }
  801. $action_desc = '订单关闭!'; // 操作明细
  802. $action_note = '管理员关闭订单!'; // 操作备注
  803. /*结束*/
  804. }
  805. // 更新订单主表
  806. $IsOrder = $this->shop_order_db->where($Where)->update($UpdateData);
  807. if (!empty($IsOrder)) {
  808. // 更新订单明细表
  809. $Data['update_time'] = getTime();
  810. $this->shop_order_details_db->where('order_id',$post['order_id'])->update($Data);
  811. // 如果是关闭订单操作则执行还原产品库存
  812. if ('gbdd' == $post['status_name']) {
  813. $UpWhere = $this->shop_order_details_db->where('order_id',$post['order_id'])->field('product_id as aid,num,data')->find();
  814. // 读取规格值ID,拼装作为更新条件
  815. $UpWhere['spec_value_id'] = unserialize($UpWhere['data'])['spec_value_id'];
  816. // 更新数据
  817. $UpData['spec_stock'] = Db::raw('spec_stock+'.($UpWhere['num']));
  818. $UpData['spec_sales_num'] = Db::raw('spec_sales_num-'.($UpWhere['num']));
  819. // 清除多余num数据
  820. unset($UpWhere['num']);
  821. // 清除多余data数据
  822. unset($UpWhere['data']);
  823. // 更新库存及销量
  824. Db::name('product_spec_value')->where($UpWhere)->update($UpData);
  825. }
  826. // 添加订单操作记录
  827. AddOrderAction($post['order_id'], 0, session('admin_id'), $order_status, $express_status, $pay_status, $action_desc, $action_note);
  828. // 判断是否为虚拟商品
  829. if ('yfk' == $post['status_name'] && $OrderData['prom_type'] == 1) {
  830. PayModel::afterVirtualProductPay($Where);
  831. }
  832. // 确认收货则执行
  833. if ('ysh' == $post['status_name']) {
  834. // 如果安装了分销插件则执行
  835. if (is_dir('./weapp/DealerPlugin/')) {
  836. // 开启分销插件则执行
  837. $weappInfo = model('Weapp')->getWeappList('DealerPlugin');
  838. if (!empty($weappInfo['status']) && 1 == $weappInfo['status']) {
  839. // 调用分销逻辑层方法
  840. $dealerCommonLogic = new \weapp\DealerPlugin\logic\DealerCommonLogic;
  841. $dealerCommonLogic->dealerOrderSettlementExecute($post['order_id'], $post['users_id']);
  842. }
  843. }
  844. // 如果安装了秒杀插件则执行
  845. if (is_dir('./weapp/Seckill/')) {
  846. $SeckillRow = model('Weapp')->getWeappList('Seckill');
  847. //is_seckill_order 只有安装了秒杀插件 shop_order表才会有这个字段
  848. if (!empty($SeckillRow) && 1 == intval($SeckillRow['status']) && !empty($order['is_seckill_order'])) {
  849. // 调用秒杀逻辑层方法
  850. $weappSeckillLogic = new \weapp\Seckill\logic\SeckillLogic;
  851. $weappSeckillLogic->confirmOrderHandle($post['order_id'], $post['users_id']);
  852. }
  853. }
  854. }
  855. $this->success('操作成功!');
  856. }
  857. }
  858. }else{
  859. $this->error('非法访问!');
  860. }
  861. }
  862. // 手动关闭订单并退款
  863. public function order_manual_refund()
  864. {
  865. if (IS_AJAX_POST) {
  866. $post = input('post.');
  867. $OrderID = intval($post['order_id']);
  868. $RefundNote = trim($post['refund_note']);
  869. if (!empty($OrderID)) {
  870. $update = [
  871. 'order_id' => $OrderID,
  872. 'order_status' => '-1',
  873. 'manual_refund' => 1,
  874. 'refund_note' => $RefundNote,
  875. 'update_time' => getTime(),
  876. ];
  877. $ResultID = $this->shop_order_db->update($update);
  878. if (!empty($ResultID)) {
  879. // 如果安装了秒杀插件则执行
  880. if (is_dir('./weapp/Seckill/')) {
  881. $SeckillRow = model('Weapp')->getWeappList('Seckill');
  882. //is_seckill_order 只有安装了秒杀插件 shop_order表才会有这个字段
  883. if (!empty($SeckillRow) && 1 == intval($SeckillRow['status']) && !empty($order['is_seckill_order'])) {
  884. // 调用秒杀逻辑层方法
  885. $users_id = $this->shop_order_db->where('order_id',$OrderID)->value('users_id');
  886. $weappSeckillLogic = new \weapp\Seckill\logic\SeckillLogic;
  887. $weappSeckillLogic->cancelOrderHandle($OrderID, $users_id);
  888. }
  889. }
  890. // 添加订单操作记录
  891. AddOrderAction($OrderID, 0, session('admin_id'), '-1', 0, 1, '关闭并退款', '管理员手动关闭订单并自行退款');
  892. // 商品库存恢复
  893. $where = [
  894. 'order_id' => $OrderID,
  895. ];
  896. $shopOrder = $this->shop_order_db->where($where)->select();
  897. model('OrderPreHandle')->restoreGoodsStock($shopOrder);
  898. // 加添订单售后信息
  899. $this->adminAddOrderService($OrderID, $RefundNote);
  900. // 返回结束
  901. $this->success('操作完成');
  902. }
  903. }
  904. }
  905. $this->error('非法访问!');
  906. }
  907. // 加添订单售后信息
  908. public function adminAddOrderService($orderID = 0, $refundNote = '')
  909. {
  910. $where = [
  911. 'order_id' => $orderID,
  912. ];
  913. // 查询订单信息
  914. $order = Db::name('shop_order')->where($where)->find();
  915. $city = get_city_name($order['city']);
  916. $district = get_area_name($order['district']);
  917. $province = get_province_name($order['province']);
  918. $order['address'] = $province . ' ' . $city . ' ' . $district . ' ' . $order['address'];
  919. // 查询订单商品信息
  920. $details = $this->shop_order_details_db->where($where)->select();
  921. if (!empty($details)) {
  922. $times = getTime();
  923. foreach ($details as $key => $value) {
  924. // 商品规格信息
  925. $value['data'] = !empty($value['data']) ? unserialize($value['data']) : [];
  926. $product_spec = !empty($value['data']['spec_value']) ? htmlspecialchars_decode(htmlspecialchars_decode($value['data']['spec_value'])) : '';
  927. // 订单售后信息
  928. $insert = [
  929. 'service_type' => 2,
  930. 'users_id' => intval($order['users_id']),
  931. 'merchant_id' => intval($order['merchant_id']),
  932. 'order_id' => intval($order['order_id']),
  933. 'order_code' => strval($order['order_code']),
  934. 'details_id' => intval($value['details_id']),
  935. 'product_id' => intval($value['product_id']),
  936. 'product_name' => strval($value['product_name']),
  937. 'product_spec' => strval($product_spec),
  938. 'product_num' => intval($value['num']),
  939. 'product_img' => strval($value['litpic']),
  940. 'content' => '商家主动退款',
  941. 'address' => strval($order['address']),
  942. 'consignee' => $order['consignee'],
  943. 'mobile' => $order['mobile'],
  944. 'manual_refund'=> 1,
  945. 'manual_time' => $times,
  946. 'refund_note' => !empty($refundNote) ? $refundNote : '商家主动退款',
  947. 'refund_price' => unifyPriceHandle($value['product_price']),
  948. 'refund_code' => 'TK' . $times . rand(10, 99),
  949. 'status' => 7,
  950. 'add_time' => $times,
  951. 'update_time' => $times,
  952. ];
  953. $resultID = Db::name('shop_order_service')->insertGetId($insert);
  954. if (!empty($resultID)) {
  955. // 更新订单明细表中对应商品为申请服务
  956. $update = [
  957. 'apply_service' => 1,
  958. 'update_time' => getTime()
  959. ];
  960. $this->shop_order_details_db->where('details_id', $value['details_id'])->update($update);
  961. // 添加订单服务记录
  962. OrderServiceLog($resultID, $order['order_id'], 0, session('admin_id'), '商家主动退款');
  963. }
  964. }
  965. }
  966. }
  967. /*
  968. * 更新管理员备注
  969. */
  970. public function update_note()
  971. {
  972. if (IS_AJAX_POST) {
  973. $post = input('post.');
  974. if (!empty($post['order_id'])) {
  975. $UpdateData = [
  976. 'admin_note' => $post['admin_note'],
  977. 'update_time' => getTime(),
  978. ];
  979. $return = $this->shop_order_db->where('order_id',$post['order_id'])->update($UpdateData);
  980. if (!empty($return)) {
  981. $this->success('保存成功!');
  982. }
  983. }else{
  984. $this->error('非法访问!');
  985. }
  986. }else{
  987. $this->error('非法访问!');
  988. }
  989. }
  990. /*
  991. * 运费模板列表
  992. */
  993. public function shipping_template()
  994. {
  995. $Where = [
  996. 'a.level' => 1,
  997. ];
  998. $region_name = input('param.region_name');
  999. if (!empty($region_name)) {
  1000. $Where['a.name'] = array('LIKE', "%{$region_name}%");
  1001. }
  1002. // 省份
  1003. $Template = Db::name('region')->field('a.id, a.name, b.template_money, b.template_id')
  1004. ->alias('a')
  1005. ->join('__SHOP_SHIPPING_TEMPLATE__ b', 'a.id = b.province_id', 'LEFT')
  1006. ->where($Where)
  1007. ->getAllWithIndex('id');
  1008. $this->assign('Template', $Template);
  1009. // 统一配送
  1010. $info = $this->shipping_template_db->where('province_id','100000')->find();
  1011. $this->assign('info', $info);
  1012. return $this->fetch('shipping_template');
  1013. }
  1014. // 订单批量删除
  1015. public function order_del()
  1016. {
  1017. $order_id = input('del_id/a');
  1018. $order_id = eyIntval($order_id);
  1019. if (IS_AJAX_POST && !empty($order_id)) {
  1020. // 条件数组
  1021. $Where = [
  1022. 'order_id' => ['IN', $order_id],
  1023. 'lang' => $this->admin_lang,
  1024. ];
  1025. // 查询数据,存在adminlog日志
  1026. $result = $this->shop_order_db->field('order_code')->where($Where)->select();
  1027. $order_code_list = get_arr_column($result, 'order_code');
  1028. // 删除订单列表数据
  1029. $return = $this->shop_order_db->where($Where)->delete();
  1030. if ($return) {
  1031. // 同步删除订单下的产品
  1032. $this->shop_order_details_db->where($Where)->delete();
  1033. // 同步删除订单下的操作记录
  1034. $this->shop_order_log_db->where($Where)->delete();
  1035. adminLog('删除订单:'.implode(',', $order_code_list));
  1036. $this->success('删除成功');
  1037. }else{
  1038. $this->error('删除失败');
  1039. }
  1040. }
  1041. $this->error('参数有误');
  1042. }
  1043. /*
  1044. * 查询会员订单数据并加载,无返回
  1045. */
  1046. function GetOrderData($order_id)
  1047. {
  1048. // 手机端后台管理插件特定使用参数
  1049. $isMobile = input('param.isMobile/d', 0);
  1050. // 获取订单数据
  1051. $OrderData = $this->shop_order_db->find($order_id);
  1052. $OrderData['add_time'] = date('Y-m-d H:i:s', $OrderData['add_time']);
  1053. $OrderData['pay_time'] = !empty($OrderData['pay_time']) ? date('Y-m-d H:i:s', $OrderData['pay_time']) : 0;
  1054. $OrderData['update_time'] = !empty($OrderData['update_time']) ? date('Y-m-d H:i:s', $OrderData['update_time']) : 0;
  1055. $OrderData['express_time'] = !empty($OrderData['express_time']) ? date('Y-m-d H:i:s', $OrderData['express_time']) : 0;
  1056. $OrderData['confirm_time'] = !empty($OrderData['confirm_time']) ? date('Y-m-d H:i:s', $OrderData['confirm_time']) : 0;
  1057. $OrderData['order_terminal_name'] = '电脑端';
  1058. if (!empty($OrderData['order_terminal']) && 2 === intval($OrderData['order_terminal'])) {
  1059. $OrderData['order_terminal_name'] = '手机端';
  1060. } else if (!empty($OrderData['order_terminal']) && 3 === intval($OrderData['order_terminal'])) {
  1061. $OrderData['order_terminal_name'] = '微信小程序';
  1062. }
  1063. // 获取会员数据
  1064. $UsersData = $this->users_db->find($OrderData['users_id']);
  1065. !empty($UsersData) && $UsersData['head_pic'] = get_head_pic($UsersData['head_pic']);
  1066. // 当前单条订单信息的会员ID,存入session,用于添加订单操作表
  1067. session('OrderUsersId', $OrderData['users_id']);
  1068. // 获取订单详细表数据
  1069. $DetailsData = $this->shop_order_details_db->where('order_id',$OrderData['order_id'])->select();
  1070. // 获取订单状态,后台专用
  1071. $admin_order_status_arr = Config::get('global.admin_order_status_arr');
  1072. // 获取订单方式名称
  1073. $pay_method_arr = Config::get('global.pay_method_arr');
  1074. // 处理订单主表的地址数据处理,显示中文名字
  1075. $OrderData['country'] = '中国';
  1076. $OrderData['province'] = get_province_name($OrderData['province']);
  1077. $OrderData['city'] = get_city_name($OrderData['city']);
  1078. $OrderData['district'] = get_area_name($OrderData['district']);
  1079. $array_new = get_archives_data($DetailsData,'product_id');
  1080. $OrderData['prom_type_virtual'] = false;
  1081. // 处理订单详细表数据处理
  1082. $total_num = 0;
  1083. $OrderData['totalAmount'] = 0;
  1084. foreach ($DetailsData as $key => $value) {
  1085. $total_num += intval($value['num']);
  1086. if ($value['prom_type'] == 1) {
  1087. $OrderData['prom_type_virtual'] = true;
  1088. }
  1089. // 产品属性处理
  1090. $value['data'] = !empty($value['data']) ? unserialize($value['data']) : [];
  1091. $DetailsData[$key]['pointsGoodsBuyField'] = !empty($value['data']['pointsGoodsBuyField']) ? json_decode($value['data']['pointsGoodsBuyField'], true) : [];
  1092. $value['data'] = htmlspecialchars_decode(htmlspecialchars_decode($value['data']['spec_value']));
  1093. // 组合数据
  1094. $value['data'] = explode('<br/>', $value['data']);
  1095. $valueData = '';
  1096. foreach ($value['data'] as $key_1 => $value_1) {
  1097. $delimiter = '';//!empty($isMobile) ? ';' : '';
  1098. if (!empty($value_1)) $valueData .= '<span>' . trim(strrchr($value_1, ':'),':') . '</span>' . $delimiter;
  1099. }
  1100. $DetailsData[$key]['product_spec'] = $value['data'] = $valueData;
  1101. // // 规制值
  1102. // $spec_value = !empty($ValueData['spec_value']) ? htmlspecialchars_decode($ValueData['spec_value']) : '';
  1103. // $spec_value = htmlspecialchars_decode($spec_value);
  1104. // // 旧参数
  1105. // $attr_value = !empty($ValueData['attr_value']) ? htmlspecialchars_decode($ValueData['attr_value']) : '';
  1106. // $attr_value = htmlspecialchars_decode($attr_value);
  1107. // // 新参数
  1108. // $attr_value_new = !empty($ValueData['attr_value_new']) ? htmlspecialchars_decode($ValueData['attr_value_new']) : '';
  1109. // $attr_value_new = htmlspecialchars_decode($attr_value_new);
  1110. // // 优先显示新参数
  1111. // $attr_value = !empty($attr_value_new) ? $attr_value_new : $attr_value;
  1112. // $DetailsData[$key]['data'] = $spec_value . $attr_value;
  1113. // 产品内页地址
  1114. $DetailsData[$key]['arcurl'] = get_arcurl($array_new[$value['product_id']]);
  1115. // 小计
  1116. $DetailsData[$key]['subtotal'] = unifyPriceHandle($value['product_price'] * $value['num']);
  1117. // 合计金额
  1118. $OrderData['totalAmount'] += $DetailsData[$key]['subtotal'];
  1119. $OrderData['totalAmount'] = unifyPriceHandle($OrderData['totalAmount']);
  1120. // 支持子目录
  1121. $DetailsData[$key]['litpic'] = handle_subdir_pic($DetailsData[$key]['litpic']);
  1122. }
  1123. // 订单类型
  1124. if (empty($OrderData['prom_type'])) {
  1125. $OrderData['prom_type_name'] = '普通订单';
  1126. }else{
  1127. $OrderData['prom_type_name'] = '虚拟订单';
  1128. }
  1129. if (!empty($OrderData['is_seckill_order'])) $OrderData['prom_type_name'] = '秒杀订单';
  1130. if (!empty($OrderData['points_shop_order'])) $OrderData['prom_type_name'] = '积分订单';
  1131. // 移动端查询物流链接
  1132. $MobileExpressUrl = "//m.kuaidi100.com/index_all.html?type=".$OrderData['express_code']."&postid=".$OrderData['express_order'];
  1133. $this->assign('MobileExpressUrl', $MobileExpressUrl);
  1134. // PC端查询物流链接
  1135. $pcExpressUrl = "https://www.kuaidi100.com/chaxun?com=".$OrderData['express_code']."&nu=".$OrderData['express_order'];
  1136. $this->assign('pcExpressUrl', $pcExpressUrl);
  1137. // 管理员备注
  1138. $adminNoteCount = !empty($OrderData['admin_note']) ? count(unserialize($OrderData['admin_note'])) : 0;
  1139. $this->assign('adminNoteCount', $adminNoteCount);
  1140. // 存在积分商城订单则执行
  1141. if (!empty($OrderData['points_shop_order'])) {
  1142. $weappInfo = model('ShopPublicHandle')->getWeappPointsShop();
  1143. if (!empty($weappInfo)) {
  1144. $list = !empty($OrderData) ? $OrderData : [];
  1145. $list['Details'] = !empty($DetailsData) ? $DetailsData : [];
  1146. $pointsShopLogic = new \weapp\PointsShop\logic\PointsShopLogic();
  1147. $pointsShopLogic->pointsShopOrderDataHandle([$list], $OrderData, $DetailsData);
  1148. }
  1149. }
  1150. // 加载数据
  1151. $this->assign('OrderData', $OrderData);
  1152. $this->assign('DetailsData', $DetailsData);
  1153. $this->assign('UsersData', $UsersData);
  1154. $this->assign('admin_order_status_arr', $admin_order_status_arr);
  1155. $this->assign('pay_method_arr', $pay_method_arr);
  1156. $this->assign('total_num', $total_num);
  1157. // 核销订单记录信息
  1158. $weappVerifyLog = [];
  1159. if (!empty($this->weappInfo)) {
  1160. $where = [
  1161. 'users_id' => intval($OrderData['users_id']),
  1162. 'order_id' => intval($OrderData['order_id']),
  1163. ];
  1164. $weappVerifyLog = Db::name('weapp_verify')->where($where)->find();
  1165. $weappVerifyLog['verify_time'] = !empty($weappVerifyLog['verify_time']) ? date('Y-m-d H:i:s', $weappVerifyLog['verify_time']) : 0;
  1166. }
  1167. $this->assign('weappVerifyLog', $weappVerifyLog);
  1168. }
  1169. // ------------------------------------------------------------------------------------------------------
  1170. // 以下所有代码都是产品规格处理逻辑 2019-07-08 陈风任
  1171. // ------------------------------------------------------------------------------------------------------
  1172. // 规格列表管理,包含新增、更新
  1173. public function spec_index()
  1174. {
  1175. if (IS_AJAX_POST) {
  1176. // 新增、更新
  1177. $post = input('post.');
  1178. // 当前时间戳
  1179. $time = getTime();
  1180. /*新增数据处理*/
  1181. $post_new = [];
  1182. foreach ($post['preset_new'] as $key => $value) {
  1183. // 规格名称不允许为空
  1184. $preset_name = $post['preset_name_'.$value][0];
  1185. if (empty($preset_name)) continue;
  1186. // 是否同步到已发布的商品规格
  1187. $spec_sync = !empty($post['spec_sync_'.$value]) ? 1 : 0;
  1188. // 排序号
  1189. $sort_order = $post['sort_order_'.$value];
  1190. // 拼装三维数组
  1191. foreach ($post['preset_value_'.$value] as $kk => $vv) {
  1192. if (empty($vv)) continue;
  1193. $post_new[$key][$kk]['preset_mark_id'] = $value; // 标记ID,一整条规格信息中的唯一标识
  1194. $post_new[$key][$kk]['preset_name'] = $preset_name;
  1195. $post_new[$key][$kk]['preset_value'] = $vv;
  1196. $post_new[$key][$kk]['spec_sync'] = $spec_sync;
  1197. $post_new[$key][$kk]['sort_order'] = $sort_order;
  1198. $post_new[$key][$kk]['lang'] = $this->admin_lang;
  1199. $post_new[$key][$kk]['add_time'] = $time;
  1200. $post_new[$key][$kk]['update_time'] = $time;
  1201. }
  1202. }
  1203. // 三维数组降为二维数组
  1204. $data_new = $this->ProductSpecLogic->ArrayDowngrade($post_new);
  1205. /* END */
  1206. /*原有数据处理*/
  1207. $post_old = [];
  1208. $spec_sync_where = $spec_sync_mark_data = $spec_sync_value_data = [];
  1209. foreach ($post['preset_old'] as $key => $value) {
  1210. // 规格名称不允许为空
  1211. $preset_name = $post['preset_name_old_'.$value][0];
  1212. if (empty($preset_name)) continue;
  1213. // 是否同步到已发布的商品规格
  1214. $spec_sync = !empty($post['spec_sync_'.$value]) ? 1 : 0;
  1215. // 排序号
  1216. $sort_order = $post['sort_order_'.$value];
  1217. // 需要同步的规格名称
  1218. if (!empty($spec_sync)) {
  1219. array_push($spec_sync_where, $value);
  1220. $spec_sync_mark_data[$value]['spec_name'] = $preset_name;
  1221. }
  1222. // 拼装三维数组
  1223. foreach ($post['preset_value_old_'.$value] as $kk => $vv) {
  1224. if (empty($vv)) continue;
  1225. $preset_id = $post['preset_id_old_'.$value][$kk];
  1226. // 如果ID是否为空
  1227. if (!empty($preset_id)) {
  1228. // 有ID则为更新
  1229. $post_old[$key][$kk]['preset_id'] = $preset_id;
  1230. // 需要同步的规格值
  1231. if (!empty($spec_sync)) $spec_sync_value_data[$preset_id]['spec_value'] = $vv;
  1232. } else {
  1233. // 无ID则为新增
  1234. $post_old[$key][$kk]['lang'] = $this->admin_lang;
  1235. $post_old[$key][$kk]['add_time'] = $time;
  1236. $post_old[$key][$kk]['preset_mark_id'] = $value; // 标记ID,一整条规格信息中的唯一标识
  1237. }
  1238. $post_old[$key][$kk]['preset_name'] = $preset_name;
  1239. $post_old[$key][$kk]['preset_value'] = $vv;
  1240. $post_old[$key][$kk]['spec_sync'] = $spec_sync;
  1241. $post_old[$key][$kk]['sort_order'] = $sort_order;
  1242. $post_old[$key][$kk]['update_time'] = $time;
  1243. }
  1244. }
  1245. // 三维数组降为二维数组
  1246. $data_old = $this->ProductSpecLogic->ArrayDowngrade($post_old);
  1247. /* END */
  1248. // 合并数组并且更新数据
  1249. $UpData = array_merge($data_old, $data_new);
  1250. model('ProductSpecPreset')->saveAll($UpData);
  1251. /*执行同步数据*/
  1252. if (!empty($spec_sync_where)) {
  1253. $w_1['spec_mark_id'] = ['IN', $spec_sync_where];
  1254. $f_1 = 'spec_id, spec_mark_id, spec_name, spec_value_id, spec_value';
  1255. $SpecMarkData = Db::name('product_spec_data')->where($w_1)->field($f_1)->order('spec_mark_id asc')->select();
  1256. foreach ($SpecMarkData as $key => $value) {
  1257. $SpecMarkData[$key]['spec_name'] = $spec_sync_mark_data[$value['spec_mark_id']]['spec_name'];
  1258. $SpecMarkData[$key]['spec_value'] = $spec_sync_value_data[$value['spec_value_id']]['spec_value'];
  1259. }
  1260. model('ProductSpecData')->saveAll($SpecMarkData);
  1261. }
  1262. /* END */
  1263. $this->success('更新成功!');
  1264. }
  1265. // 查询规格数据
  1266. $PresetData = $this->product_spec_preset_db->where('lang',$this->admin_lang)->order('sort_order asc, preset_id asc')->select();
  1267. // 数组转化
  1268. $ResultData = $this->ProductSpecLogic->GetPresetData($PresetData);
  1269. // 获取预设规格中最大的标记MarkId
  1270. $PresetMarkId = model('ProductSpecPreset')->GetMaxPresetMarkId();
  1271. // 加载参数
  1272. $this->assign('info', $ResultData);
  1273. $this->assign('PresetMarkId', $PresetMarkId);
  1274. return $this->fetch('spec_index');
  1275. }
  1276. // 规格列表管理,包含新增、更新
  1277. public function spec_template()
  1278. {
  1279. if (IS_AJAX_POST) {
  1280. // 新增、更新
  1281. $post = input('post.');
  1282. // 当前时间戳
  1283. $time = getTime();
  1284. /*新增数据处理*/
  1285. $post_new = [];
  1286. foreach ($post['preset_new'] as $key => $value) {
  1287. // 规格名称不允许为空
  1288. $preset_name = $post['preset_name_'.$value][0];
  1289. if (empty($preset_name)) continue;
  1290. // 是否同步到已发布的商品规格
  1291. $spec_sync = !empty($post['spec_sync_'.$value]) ? 1 : 0;
  1292. // 排序号
  1293. $sort_order = $post['sort_order_'.$value];
  1294. // 拼装三维数组
  1295. foreach ($post['preset_value_'.$value] as $kk => $vv) {
  1296. if (empty($vv)) continue;
  1297. $post_new[$key][$kk]['preset_mark_id'] = $value; // 标记ID,一整条规格信息中的唯一标识
  1298. $post_new[$key][$kk]['preset_name'] = $preset_name;
  1299. $post_new[$key][$kk]['preset_value'] = $vv;
  1300. $post_new[$key][$kk]['spec_sync'] = $spec_sync;
  1301. $post_new[$key][$kk]['sort_order'] = $sort_order;
  1302. $post_new[$key][$kk]['lang'] = $this->admin_lang;
  1303. $post_new[$key][$kk]['add_time'] = $time;
  1304. $post_new[$key][$kk]['update_time'] = $time;
  1305. }
  1306. }
  1307. // 三维数组降为二维数组
  1308. $data_new = $this->ProductSpecLogic->ArrayDowngrade($post_new);
  1309. /* END */
  1310. /*原有数据处理*/
  1311. $post_old = [];
  1312. $spec_sync_where = $spec_sync_mark_data = $spec_sync_value_data = [];
  1313. foreach ($post['preset_old'] as $key => $value) {
  1314. // 规格名称不允许为空
  1315. $preset_name = $post['preset_name_old_'.$value][0];
  1316. if (empty($preset_name)) continue;
  1317. // 是否同步到已发布的商品规格
  1318. $spec_sync = !empty($post['spec_sync_'.$value]) ? 1 : 0;
  1319. // 排序号
  1320. $sort_order = $post['sort_order_'.$value];
  1321. // 需要同步的规格名称
  1322. if (!empty($spec_sync)) {
  1323. array_push($spec_sync_where, $value);
  1324. $spec_sync_mark_data[$value]['spec_name'] = $preset_name;
  1325. }
  1326. // 拼装三维数组
  1327. foreach ($post['preset_value_old_'.$value] as $kk => $vv) {
  1328. if (empty($vv)) continue;
  1329. $preset_id = $post['preset_id_old_'.$value][$kk];
  1330. // 如果ID是否为空
  1331. if (!empty($preset_id)) {
  1332. // 有ID则为更新
  1333. $post_old[$key][$kk]['preset_id'] = $preset_id;
  1334. // 需要同步的规格值
  1335. if (!empty($spec_sync)) $spec_sync_value_data[$preset_id]['spec_value'] = $vv;
  1336. } else {
  1337. // 无ID则为新增
  1338. $post_old[$key][$kk]['lang'] = $this->admin_lang;
  1339. $post_old[$key][$kk]['add_time'] = $time;
  1340. $post_old[$key][$kk]['preset_mark_id'] = $value; // 标记ID,一整条规格信息中的唯一标识
  1341. }
  1342. $post_old[$key][$kk]['preset_name'] = $preset_name;
  1343. $post_old[$key][$kk]['preset_value'] = $vv;
  1344. $post_old[$key][$kk]['spec_sync'] = $spec_sync;
  1345. $post_old[$key][$kk]['sort_order'] = $sort_order;
  1346. $post_old[$key][$kk]['update_time'] = $time;
  1347. }
  1348. }
  1349. // 三维数组降为二维数组
  1350. $data_old = $this->ProductSpecLogic->ArrayDowngrade($post_old);
  1351. /* END */
  1352. // 合并数组并且更新数据
  1353. $UpData = array_merge($data_old, $data_new);
  1354. model('ProductSpecPreset')->saveAll($UpData);
  1355. /*执行同步数据*/
  1356. if (!empty($spec_sync_where)) {
  1357. $w_1['spec_mark_id'] = ['IN', $spec_sync_where];
  1358. $f_1 = 'spec_id, spec_mark_id, spec_name, spec_value_id, spec_value';
  1359. $SpecMarkData = Db::name('product_spec_data')->where($w_1)->field($f_1)->order('spec_mark_id asc')->select();
  1360. foreach ($SpecMarkData as $key => $value) {
  1361. $SpecMarkData[$key]['spec_name'] = $spec_sync_mark_data[$value['spec_mark_id']]['spec_name'];
  1362. $SpecMarkData[$key]['spec_value'] = $spec_sync_value_data[$value['spec_value_id']]['spec_value'];
  1363. }
  1364. model('ProductSpecData')->saveAll($SpecMarkData);
  1365. }
  1366. /* END */
  1367. $this->success('更新成功!');
  1368. }
  1369. // 查询规格数据
  1370. $PresetData = $this->product_spec_preset_db->where('lang',$this->admin_lang)->order('sort_order asc, preset_id asc')->select();
  1371. // 数组转化
  1372. $ResultData = $this->ProductSpecLogic->GetPresetData($PresetData);
  1373. // 获取预设规格中最大的标记MarkId
  1374. $PresetMarkId = model('ProductSpecPreset')->GetMaxPresetMarkId();
  1375. // 加载参数
  1376. $this->assign('info', $ResultData);
  1377. $this->assign('PresetMarkId', $PresetMarkId);
  1378. return $this->fetch('spec_template');
  1379. }
  1380. // 删除规格名称\规格值
  1381. public function spec_delete()
  1382. {
  1383. if (IS_AJAX_POST) {
  1384. $post = input('post.');
  1385. $where = $this->ProductSpecLogic->GetDeleteSpecWhere($post);
  1386. if (!empty($where)) {
  1387. $result = $this->product_spec_preset_db->where($where)->delete();
  1388. if (!empty($result)) {
  1389. $this->success('删除成功!');
  1390. }
  1391. }
  1392. $this->error('删除失败!');
  1393. }
  1394. }
  1395. // 选中规格名称,追加html到页面展示
  1396. public function spec_select()
  1397. {
  1398. if (IS_AJAX_POST) {
  1399. $post = input('post.');
  1400. // 当选中的规格大类大于等于三个则不允许再添加
  1401. if (3 == count(session('spec_arr'))) $this->error('最多只能添加三种规格大类');
  1402. // 获取预设规格标记ID数组
  1403. $PresetMarkIdArray = $this->ProductSpecLogic->GetPresetMarkIdArray($post);
  1404. // 拼装预设名称下拉选项
  1405. if (!empty($PresetMarkIdArray)) {
  1406. // 添加选中的规格数据
  1407. model('ProductSpecData')->PresetSpecAddData($post);
  1408. // 拼装更新预设名称下拉选项
  1409. $Result = $this->ProductSpecLogic->GetPresetNameOption($PresetMarkIdArray, $post);
  1410. } else {
  1411. $this->error('最多只能添加三种规格大类!');
  1412. }
  1413. if (isset($post['aid']) && !empty($post['aid'])) {
  1414. $ResultData = $this->ProductSpecLogic->GetPresetValueOption('', $post['spec_mark_id'], $post['aid'], 2);
  1415. $PresetName = $ResultData['PresetName'];
  1416. $PresetValueOption = $ResultData['PresetValueOption'];
  1417. } else {
  1418. // 拼装预设值下拉选项
  1419. $PresetValue = $this->product_spec_preset_db->where('preset_mark_id','IN',$post['preset_mark_id'])->field('preset_id,preset_name,preset_value')->select();
  1420. $PresetName = $PresetValue[0]['preset_name'];
  1421. $PresetValueOption = $this->ProductSpecLogic->GetPresetValueOption($PresetValue);
  1422. }
  1423. if (isset($post['aid']) && !empty($post['aid'])) {
  1424. // 结果返回
  1425. $ReturnHtml = [
  1426. 'preset_name' => $PresetName,
  1427. 'preset_name_option' => $Result['Option'],
  1428. 'spec_mark_id_arr' => $Result['MarkId'],
  1429. 'preset_value_option' => $PresetValueOption,
  1430. ];
  1431. } else {
  1432. // 结果返回
  1433. $ReturnHtml = [
  1434. 'preset_name' => $PresetName,
  1435. 'preset_name_option' => $Result['Option'],
  1436. 'preset_mark_id_arr' => $Result['MarkId'],
  1437. 'preset_value_option' => $PresetValueOption,
  1438. ];
  1439. }
  1440. $this->success('加载成功!', null, $ReturnHtml);
  1441. }
  1442. }
  1443. // 当规格库更新后,调用此方式及时更新选择预设规格的下拉框信息及规格框信息
  1444. public function update_spec_info()
  1445. {
  1446. if (IS_AJAX_POST) {
  1447. $post = input('post.');
  1448. // 拼装更新预设名称下拉选项
  1449. $ResultData = $this->ProductSpecLogic->GetPresetNameOption($post['preset_mark_id_arr']);
  1450. // 获取规格拼装后的html表格
  1451. $ResultArray = $this->ProductSpecLogic->GetPresetSpecAssembly($post);
  1452. // 结果返回
  1453. if (isset($post['aid']) && !empty($post['aid'])) {
  1454. $ReturnHtml = [
  1455. 'HtmlTable' => $ResultArray['HtmlTable'],
  1456. 'spec_name_option' => $ResultData['Option'],
  1457. 'spec_mark_id_arr' => $ResultArray['PresetMarkIdArray'],
  1458. ];
  1459. }else{
  1460. // 拼装更新预设名称下拉选项
  1461. $where = [
  1462. 'preset_mark_id' => ['IN', $post['preset_mark_id_arr']],
  1463. ];
  1464. $PresetData = $this->product_spec_preset_db->where($where)->order('preset_id asc')->select();
  1465. $sessionData = session('spec_arr');
  1466. foreach ($PresetData as $key => $value) {
  1467. if (!empty($sessionData[$value['preset_mark_id']])) {
  1468. if (in_array($value['preset_id'], $sessionData[$value['preset_mark_id']])) {
  1469. unset($PresetData[$key]);
  1470. }
  1471. }
  1472. }
  1473. $PresetData = group_same_key($PresetData, 'preset_mark_id');
  1474. $result = [];
  1475. foreach ($PresetData as $key => $value) {
  1476. $result[$key] .= "<option value='0'>选择规格值</option>";
  1477. if(!empty($value)){
  1478. foreach($value as $sub_value){
  1479. $result[$key] .= "<option value='{$sub_value['preset_id']}'>{$sub_value['preset_value']}</option>";
  1480. }
  1481. }
  1482. }
  1483. $ReturnHtml = [
  1484. 'HtmlTable' => $ResultArray['HtmlTable'],
  1485. 'preset_name_option' => $ResultData['Option'],
  1486. 'preset_mark_id_arr' => $ResultArray['PresetMarkIdArray'],
  1487. 'preset_value_id' => explode(',', $post['preset_mark_id_arr']),
  1488. 'preset_value_option' => $result,
  1489. ];
  1490. }
  1491. $this->success('更新成功!', null, $ReturnHtml);
  1492. }
  1493. }
  1494. // 获取或更新规格组合的数据
  1495. // preset_id:预设值ID
  1496. // preset_mark_id:预设参数标记ID,同一预设规格名称下的所有规格值统一使用,可理解为规格名称唯一ID。
  1497. public function assemble_spec_data()
  1498. {
  1499. if (IS_AJAX_POST) {
  1500. $post = input('post.');
  1501. // 刷新或重新进入产品添加页则清除关于产品session
  1502. if (isset($post['initialization']) && !empty($post['initialization'])) {
  1503. session('spec_arr', null);
  1504. $this->success('初始化完成');
  1505. }
  1506. // 若清除一整条规格信息则清除session中相应的数据并且重置规格名称下拉框选项
  1507. $ResultArray = $this->ProductSpecLogic->GetResetPresetNameOption($post);
  1508. // 删除单个规格值则清除session对应的值
  1509. $ValueArray = $this->ProductSpecLogic->ClearSpecValueID($post);
  1510. // 把session中的数据和提交的数据组合
  1511. $SpecArray = $this->ProductSpecLogic->GetSessionPostArrayMerge($post);
  1512. if (isset($SpecArray['error']) && !empty($SpecArray['error'])) $this->error($SpecArray['error']);
  1513. // 获取规格拼装后的html表格
  1514. if (isset($post['aid']) && !empty($post['aid'])) {
  1515. // 编辑
  1516. $HtmlTable = $this->ProductSpecLogic->SpecAssemblyEdit($SpecArray, $post['aid']);
  1517. } else {
  1518. // 新增
  1519. $HtmlTable = $this->ProductSpecLogic->SpecAssembly($SpecArray);
  1520. }
  1521. if (!empty($ValueArray['Option'])) {
  1522. // 删除规格值后的规格值下拉框
  1523. $PresetValueOption = $ValueArray['Option'];
  1524. $ResultValue['Value'] = null;
  1525. } else {
  1526. $ResultValue = model('ProductSpecPreset')->GetPresetNewData(session('spec_arr'), $post);
  1527. // 获取新增规格值后的下拉框
  1528. if (empty($post['aid'])) {
  1529. $PresetValueOption = $this->ProductSpecLogic->GetPresetValueOption($ResultValue['Option']);
  1530. } else {
  1531. $PresetValueOption = $ResultValue['Option'];
  1532. }
  1533. }
  1534. // 返回数据
  1535. $ReturnData = [
  1536. 'HtmlTable' => $HtmlTable,
  1537. 'PresetNameOption' => $ResultArray['Option'],
  1538. 'PresetMarkIdArray' => $ResultArray['MarkId'],
  1539. 'SelectPresetValue' => $ResultValue['Value'],
  1540. 'PresetValueOption' => $PresetValueOption,
  1541. ];
  1542. $this->success('加载成功!', null, $ReturnData);
  1543. }
  1544. }
  1545. // 同步规格值到产品规格中,刷新规格值下拉框
  1546. public function refresh_spec_value()
  1547. {
  1548. if (IS_AJAX_POST) {
  1549. $post = input('post.');
  1550. // 是否提交完整数据
  1551. if (empty($post['spec_mark_id']) || empty($post['aid'])) $this->error('数据有误,同步失败,请刷新重试!');
  1552. /*查询产品已选规格数据*/
  1553. $where = [
  1554. 'aid' => $post['aid'],
  1555. 'spec_mark_id' => $post['spec_mark_id'],
  1556. ];
  1557. $SpecData = Db::name('product_spec_data')->where($where)->order('spec_value_id asc')->select();
  1558. // 以规格值ID为键名
  1559. $SpecData = group_same_key($SpecData, 'spec_value_id');
  1560. /* END */
  1561. /*查询规格库数据*/
  1562. $where = [
  1563. 'preset_mark_id' => $post['spec_mark_id'],
  1564. ];
  1565. $PresetData = $this->product_spec_preset_db->where($where)->order('preset_id asc')->select();
  1566. /* END */
  1567. // 初始化数组
  1568. $AddData = $UpData = $SpecIds = $UpSpecWhere = $UpSpecName = [];
  1569. // 数据处理
  1570. foreach ($PresetData as $pd_k => $pd_v) {
  1571. if (!empty($SpecData[$pd_v['preset_id']]) && $pd_v['preset_name'] != $SpecData[$pd_v['preset_id']][0]['spec_name']) {
  1572. // 更新规格名称数组
  1573. if (empty($UpSpecWhere) && empty($UpSpecName)) {
  1574. $UpSpecWhere = [
  1575. 'aid' => $post['aid'],
  1576. 'spec_mark_id' => $pd_v['preset_mark_id'],
  1577. ];
  1578. $UpSpecName = [
  1579. 'spec_name' => $pd_v['preset_name'],
  1580. ];
  1581. }
  1582. }
  1583. if (empty($SpecData[$pd_v['preset_id']])) {
  1584. // 添加规格值数据
  1585. $AddData[] = [
  1586. 'aid' => $post['aid'],
  1587. 'spec_mark_id' => $pd_v['preset_mark_id'],
  1588. 'spec_name' => $pd_v['preset_name'],
  1589. 'spec_value_id' => $pd_v['preset_id'],
  1590. 'spec_value' => $pd_v['preset_value'],
  1591. 'spec_is_select' => 0,
  1592. 'lang' => $this->admin_lang,
  1593. 'add_time' => getTime(),
  1594. 'update_time' => getTime(),
  1595. ];
  1596. } else if (!empty($SpecData[$pd_v['preset_id']]) && $pd_v['preset_value'] != $SpecData[$pd_v['preset_id']][0]['spec_value']) {
  1597. // 更新规格值数据
  1598. $UpData[] = [
  1599. 'spec_id' => $SpecData[$pd_v['preset_id']][0]['spec_id'],
  1600. 'spec_mark_id' => $pd_v['preset_mark_id'],
  1601. 'spec_name' => $pd_v['preset_name'],
  1602. 'spec_value_id' => $pd_v['preset_id'],
  1603. 'spec_value' => $pd_v['preset_value'],
  1604. 'update_time' => getTime(),
  1605. ];
  1606. // 删除产品已选规格表中对应需要更新的规格值数据
  1607. unset($SpecData[$pd_v['preset_id']]);
  1608. } else {
  1609. // 删除规格库中不存在的规格值数据
  1610. unset($SpecData[$pd_v['preset_id']]);
  1611. }
  1612. }
  1613. // 合并添加、编辑数据,统一处理
  1614. $SaveData = array_merge($AddData, $UpData);
  1615. /*处理需要删除的规格值数据*/
  1616. if (!empty($SpecData)) {
  1617. $DelIsSelect = 0;
  1618. foreach ($SpecData as $key => $value) {
  1619. $SpecIds[] = $value[0]['spec_id'];
  1620. if (1 == $value[0]['spec_is_select']) {
  1621. $DelIsSelect = 1;
  1622. }
  1623. $spec_mark_id = $value[0]['spec_mark_id'];
  1624. }
  1625. }
  1626. /* END */
  1627. $HtmlTable = $SpecMarks = '';
  1628. if (!empty($SpecIds)) {
  1629. // 删除废弃的规格值数据
  1630. Db::name('product_spec_data')->where('spec_id', 'IN', $SpecIds)->delete();
  1631. if (1 == $DelIsSelect) {
  1632. session('spec_arr', null);
  1633. $SpecWhere = [
  1634. 'aid' => $post['aid'],
  1635. 'lang' => $this->admin_lang,
  1636. 'spec_is_select' => 1,// 已选中的
  1637. ];
  1638. $order = 'spec_value_id asc, spec_id asc';
  1639. $product_spec_data = Db::name('product_spec_data')->where($SpecWhere)->order($order)->select();
  1640. if (!empty($product_spec_data)) {
  1641. $spec_arr_new = group_same_key($product_spec_data, 'spec_mark_id');
  1642. $DelAllSpec = $spec_mark_id;
  1643. foreach ($spec_arr_new as $key => $value) {
  1644. $spec_mark_id_arr[] = $key;
  1645. for ($i=0; $i<count($value); $i++) {
  1646. $spec_arr_new[$key][$i] = $value[$i]['spec_value_id'];
  1647. }
  1648. if ($spec_mark_id == $key) {
  1649. $DelAllSpec = 0;
  1650. }
  1651. }
  1652. session('spec_arr', $spec_arr_new);
  1653. $HtmlTable = $this->ProductSpecLogic->SpecAssemblyEdit($spec_arr_new, $post['aid']);
  1654. $SpecMarks = implode(',', $spec_mark_id_arr);
  1655. }
  1656. }
  1657. }
  1658. if (!empty($SaveData)) {
  1659. // 批量保存更新新规格
  1660. model('ProductSpecData')->saveAll($SaveData);
  1661. }
  1662. if (!empty($UpSpecWhere) && !empty($UpSpecName)) {
  1663. // 更新当前产品下对应的规格名称
  1664. Db::name('product_spec_data')->where($UpSpecWhere)->update($UpSpecName);
  1665. if (empty($UpData)) {
  1666. $UpData[0] = [
  1667. 'spec_name' => $UpSpecName['spec_name'],
  1668. 'spec_mark_id' => $UpSpecWhere['spec_mark_id']
  1669. ];
  1670. }
  1671. }
  1672. $ValueOption = $this->ProductSpecLogic->GetPresetValueOption('', $post['spec_mark_id'], $post['aid']);
  1673. $ResultData = [
  1674. 'UpData' => $UpData,
  1675. 'SpecIds' => $SpecIds,
  1676. 'HtmlTable' => $HtmlTable,
  1677. 'SpecMarks' => $SpecMarks,
  1678. 'DelAllSpec' => $DelAllSpec,
  1679. 'ValueOption' => $ValueOption,
  1680. ];
  1681. $this->success('同步成功,规格值已刷新!', null, $ResultData);
  1682. }
  1683. }
  1684. // 新增产品时更新同步规格数据
  1685. public function refresh_preset_value()
  1686. {
  1687. if (IS_AJAX_POST) {
  1688. $post = input('post.');
  1689. if (!empty($post)) {
  1690. $HtmlTable = $DelAllPreset = $PresetData = $MarkData = '';
  1691. if ((isset($post['mark_mark_ids']) && !empty($post['mark_mark_ids'])) || (isset($post['mark_preset_ids']) && !empty($post['mark_preset_ids']))) {
  1692. if (!empty($post['mark_mark_ids'])) {
  1693. $MarkData = $this->product_spec_preset_db->where('preset_mark_id', 'IN', $post['mark_mark_ids'])->field('preset_mark_id, preset_name')->select();
  1694. }
  1695. if (!empty($post['mark_preset_ids'])) {
  1696. $PresetData = $this->product_spec_preset_db->where('preset_id', 'IN', $post['mark_preset_ids'])->field('preset_id, preset_value')->select();
  1697. }
  1698. } else {
  1699. $DelAllPreset = 0;
  1700. $spec_arr_ses = session('spec_arr');
  1701. foreach ($spec_arr_ses[$post['preset_mark_id']] as $key => $value) {
  1702. if ($value == $post['preset_id']) {
  1703. unset($spec_arr_ses[$post['preset_mark_id']][$key]);
  1704. }
  1705. }
  1706. if (empty($spec_arr_ses[$post['preset_mark_id']])) {
  1707. unset($spec_arr_ses[$post['preset_mark_id']]);
  1708. $count = $this->product_spec_preset_db->where('preset_mark_id', $post['preset_mark_id'])->count();
  1709. if (empty($count)) {
  1710. $DelAllPreset = 1;
  1711. }
  1712. }
  1713. session('spec_arr',$spec_arr_ses);
  1714. $HtmlTable = $this->ProductSpecLogic->SpecAssembly($spec_arr_ses);
  1715. }
  1716. $ResultData = [
  1717. 'MarkData' => $MarkData,
  1718. 'HtmlTable' => $HtmlTable,
  1719. 'PresetData' => $PresetData,
  1720. 'DelAllPreset' => $DelAllPreset,
  1721. ];
  1722. $this->success('同步成功!', null, $ResultData);
  1723. }
  1724. }
  1725. }
  1726. // 检查是否最新的购物车标签
  1727. public function VerifyLatestTemplate()
  1728. {
  1729. // 验证最新模板
  1730. $ResultData = VerifyLatestTemplate();
  1731. if (empty($ResultData)) {
  1732. // 更新开启多规格
  1733. getUsersConfigData('shop', ['shop_open_spec' => 1]);
  1734. // 返回提示
  1735. $this->success('模板检测通过,规格已开启!');
  1736. }else{
  1737. if (5 == count($ResultData)) {
  1738. $msg = '未检测到规格标签,请根据提示手工调用后再重新验证!';
  1739. }else{
  1740. $msg = '规格标签缺少变量:<br/><span style="color: red;">'.implode(', ', $ResultData).'</span><br/>请检查模板核实后再次验证!';
  1741. }
  1742. // 更新关闭多规格
  1743. getUsersConfigData('shop', ['shop_open_spec' => 0]);
  1744. // 返回提示
  1745. $this->error($msg);
  1746. }
  1747. }
  1748. // 暂时已废弃,暂时不清理删除代码
  1749. public function FindSmptConfig() {
  1750. $Smtp = tpCache('smtp');
  1751. if (empty($Smtp['smtp_server']) || empty($Smtp['smtp_port']) || empty($Smtp['smtp_user']) || empty($Smtp['smtp_pwd']) || empty($Smtp['smtp_from_eamil'])) {
  1752. $this->error('邮箱配置尚未配置完成,前往配置?', url('System/api_conf'));
  1753. } else {
  1754. // tpCache('smtp', [input('post.field') => 1]);
  1755. $this->success('配置完成');
  1756. }
  1757. }
  1758. // 未付款订单改价
  1759. public function order_change_price()
  1760. {
  1761. if (IS_AJAX_POST) {
  1762. $post = input('post.');
  1763. if (empty($post['order_id']) || empty($post['order_amount'])) $this->error('操作错误,刷新重试');
  1764. // 更新条件
  1765. $where = [
  1766. 'order_id' => $post['order_id'],
  1767. 'order_status' => 0
  1768. ];
  1769. // 更新数据
  1770. $Code = date('Ymd') . getTime() . rand(10, 100);
  1771. $update = [
  1772. 'order_code' => $Code,
  1773. 'update_time' => getTime(),
  1774. 'order_amount' => $post['order_amount']
  1775. ];
  1776. // 更新操作
  1777. $ResultID = $this->shop_order_db->where($where)->update($update);
  1778. // 更新后续操作
  1779. if (!empty($ResultID)) {
  1780. // 添加订单的操作记录
  1781. $action_note = '应付金额改为:' . $post['order_amount'] . ',原价:' . $post['order_amount_old'];
  1782. AddOrderAction($post['order_id'], 0, session('admin_id'), 0, 0, 0, '商家改价!', $action_note);
  1783. $this->success('改价完成');
  1784. } else {
  1785. $this->error('改价失败,刷新重试');
  1786. }
  1787. }
  1788. }
  1789. /**
  1790. * 营销功能
  1791. * @return [type] [description]
  1792. */
  1793. public function market_index()
  1794. {
  1795. return $this->fetch();
  1796. }
  1797. //会员编辑 订单数列表
  1798. public function users_edit_order_index()
  1799. {
  1800. // 初始化数组和条件
  1801. $where = [
  1802. 'a.lang' => $this->admin_lang,
  1803. ];
  1804. // 会员编辑专用 - 筛选
  1805. $users_id = input('users_id/d');
  1806. if (!empty($users_id)) {
  1807. $where['a.users_id'] = $users_id;
  1808. $where['a.order_status'] = 3;
  1809. }
  1810. // 订单号查询
  1811. $order_code = input('order_code/s');
  1812. if (!empty($order_code)) $where['a.order_code'] = ['LIKE', "%{$order_code}%"];
  1813. // 分页查询
  1814. $count = $this->shop_order_db->alias('a')->where($where)->count('order_id');
  1815. $pageObj = new Page($count, config('paginate.list_rows'));
  1816. // 订单主表数据查询
  1817. $list = $this->shop_order_db->alias('a')
  1818. ->field('a.*, b.username as u_username, b.nickname as u_nickname, b.mobile as u_mobile')
  1819. ->where($where)
  1820. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1821. ->order('a.order_id desc')
  1822. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  1823. ->select();
  1824. if (empty($list) && !empty($order_code)) {
  1825. // 通过商品名称查询订单号
  1826. $where_1['product_name'] = ['LIKE', "%{$order_code}%"];
  1827. $order_ids = $this->shop_order_details_db->where($where_1)->group('order_id')->column('order_id');
  1828. // 重新查询订单主表
  1829. unset($where['a.order_code']);
  1830. $where['a.order_id'] = ['IN', $order_ids];
  1831. // 分页查询
  1832. $count = $this->shop_order_db->alias('a')->where($where)->count('order_id');
  1833. $pageObj = new Page($count, config('paginate.list_rows'));
  1834. // 订单主表数据查询
  1835. $list = $this->shop_order_db->alias('a')
  1836. ->field('a.*, b.username as u_username, b.nickname as u_nickname, b.mobile as u_mobile')
  1837. ->where($where)
  1838. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1839. ->order('a.order_id desc')
  1840. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  1841. ->select();
  1842. }
  1843. $order_ids = [];
  1844. $OrderReminderID = [];
  1845. foreach ($list as $key => $value) {
  1846. array_push($order_ids, $value['order_id']);
  1847. if (1 == $value['order_status']) array_push($OrderReminderID, $value['order_id']);
  1848. }
  1849. // 处理订单详情数据
  1850. $where = [
  1851. 'a.order_id' => ['IN', $order_ids]
  1852. ];
  1853. $DetailsData = $this->shop_order_details_db->alias('a')
  1854. ->field('a.*, b.service_id, b.status')
  1855. ->where($where)
  1856. ->join('__SHOP_ORDER_SERVICE__ b', 'a.details_id = b.details_id', 'LEFT')
  1857. ->order('details_id asc')
  1858. ->select();
  1859. $ArchivesData = get_archives_data($DetailsData, 'product_id');
  1860. $OrderServiceStatus = Config::get('global.order_service_status');
  1861. foreach ($DetailsData as $key => $value) {
  1862. // 售后信息处理
  1863. $value['service_id'] = !empty($value['service_id']) ? $value['service_id'] : 0;
  1864. $value['status'] = !empty($value['status']) ? $value['status'] : 0;
  1865. $value['status_name'] = !empty($value['status']) ? $OrderServiceStatus[$value['status']] : '';
  1866. // 产品属性处理
  1867. $value['data'] = unserialize($value['data']);
  1868. $value['data'] = htmlspecialchars_decode(htmlspecialchars_decode($value['data']['spec_value']));
  1869. // 组合数据
  1870. $value['data'] = explode('<br/>', $value['data']);
  1871. $valueData = '';
  1872. foreach ($value['data'] as $key_1 => $value_1) {
  1873. if (!empty($value_1)) $valueData .= '<span>' . trim(strrchr($value_1, ':'),':') . '</span>';
  1874. }
  1875. $value['data'] = $valueData;
  1876. $value['arcurl'] = get_arcurl($ArchivesData[$value['product_id']]);
  1877. $value['litpic'] = handle_subdir_pic(get_default_pic($value['litpic']));
  1878. $DetailsData[$key] = $value;
  1879. }
  1880. // 把订单详情数据植入订单数据
  1881. $DetailsDataGroup = group_same_key($DetailsData, 'order_id');
  1882. foreach ($list as $key => $value) {
  1883. // 处理会员昵称
  1884. $value['u_nickname'] = !empty($value['u_nickname']) ? $value['u_nickname'] : $value['u_username'];
  1885. // 处理订单详情数据
  1886. $value['Details'] = $DetailsDataGroup[$value['order_id']];
  1887. // 商品条数
  1888. $value['rowspan'] = count($value['Details']);
  1889. // 添加时间
  1890. $value['add_time'] = date('Y-m-d H:i:s', $value['add_time']);
  1891. // 更新时间
  1892. $value['update_time'] = date('Y-m-d H:i:s', $value['update_time']);
  1893. // 重新赋值数据
  1894. $list[$key] = $value;
  1895. }
  1896. // 分页显示输出
  1897. $pageStr = $pageObj->show();
  1898. // 数据加载
  1899. $this->assign('list', $list);
  1900. $this->assign('page', $pageStr);
  1901. $this->assign('pager', $pageObj);
  1902. return $this->fetch('member/edit/order_index');
  1903. }
  1904. //前台改变产品类型,被取消的类型的商品将会统一下架处理,这里返回受影响的商品数量
  1905. public function get_shop_type_arc()
  1906. {
  1907. $cancel_type = input('param.cancel_type/s');
  1908. $cancel_type = explode(',',$cancel_type);
  1909. $where_prom_type = [];
  1910. if (in_array(0,$cancel_type)) $where_prom_type[] = 0;
  1911. if (in_array(1,$cancel_type)) {
  1912. $where_prom_type[] = 1;
  1913. $where_prom_type[] = 2;
  1914. $where_prom_type[] = 3;
  1915. }
  1916. if (in_array(2,$cancel_type)) $where_prom_type[] = 4;
  1917. $where['channel'] = 2;
  1918. $where['is_del'] = 0;
  1919. $where['arcrank'] = ['>',-1];
  1920. $where['prom_type'] = ['in',$where_prom_type];
  1921. $count = Db::name('archives')->where($where)->count();
  1922. $this->success('success','',$count);
  1923. }
  1924. // 订单确认核销
  1925. public function verify()
  1926. {
  1927. if (IS_AJAX_POST && !empty($this->weappInfo)) {
  1928. // 开启核销插件则执行
  1929. if (!empty($this->weappInfo['status']) && 1 === intval($this->weappInfo['status'])) {
  1930. // 调用核销逻辑层方法
  1931. $post = input('post.');
  1932. $verifyLogic = new \weapp\Verify\logic\VerifyLogic;
  1933. $verifyLogic->verifyOrderConfirmHandle($post, $this->weappInfo);
  1934. }
  1935. $this->error('请先开启核销插件');
  1936. }
  1937. $this->error('请先安装核销插件');
  1938. }
  1939. public function shopOrderPreHandle()
  1940. {
  1941. if (IS_AJAX_POST) {
  1942. model('OrderPreHandle')->eyou_shopOrderPreHandle(0, getUsersConfigData('all'), 'admin');
  1943. $this->success('订单处理完成');
  1944. }
  1945. }
  1946. }