mobile_order.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','clipboard'],
  2. function ($, undefined, Backend, Table, Form,clipboard) {
  3. var Controller = {
  4. index: async function () {
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'mobile_order/index' + location.search,
  9. add_url: 'mobile_order/add',
  10. edit_url: 'mobile_order/edit',
  11. del_url: 'mobile_order/del',
  12. multi_url: 'mobile_order/multi',
  13. import_url: 'mobile_order/import',
  14. show_open_data_url: 'mobile_order/show_open_data',
  15. table: 'mobile_order',
  16. }
  17. });
  18. var table = $("#table");
  19. table.on('post-common-search.bs.table', function (event, table) {
  20. var form = $("form", table.$commonsearch);
  21. $("input[name='s_id']", form).addClass("selectpage").data("source", "auth/admin/index2").data("primaryKey", "id").data("params",{"custom[proxy]":"0","custom[sub]":"1"}).data("field", "nickname").data("orderBy", "id asc");
  22. Form.events.cxselect(form);
  23. Form.events.selectpage(form);
  24. });
  25. let is_proxy = Config.is_proxy;
  26. let is_proxy_operate = false;
  27. let is_proxy_operate_eq = false;
  28. if(is_proxy==0){
  29. is_proxy_operate = 'LIKE';
  30. is_proxy_operate_eq = '=';
  31. }
  32. let clip=new clipboard('.btn-pay_link',{
  33. text(a){
  34. let link=$(a).data('link')
  35. return link
  36. }
  37. })
  38. clip.on('success',function (){
  39. parent.layer.msg('复制成功')
  40. })
  41. //订单信息复制
  42. let order_clip=new clipboard('.btn-order_link',{
  43. text(a){
  44. // let link=$(a).data('link').replace(/<[^>]*>/g, '')
  45. let link=$(a).data('link');
  46. // console.log(JSON.stringify(link));
  47. return link + ''
  48. }
  49. })
  50. console.log(order_clip,'22222222')
  51. order_clip.on('success',function (){
  52. console.log(order_clip);
  53. parent.layer.msg('复制成功')
  54. })
  55. let status = await $.getJSON('mobile_order/status');
  56. let statusColor={};
  57. let colors=['label-daifukuan','label-info','label-danger','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success','label-default','label-danger','label-info','label-warning','label-primary','label-success'];
  58. Object.keys(status).forEach((item,idx)=>{
  59. statusColor[item]=colors[idx];
  60. });
  61. statusColor[50]='label-default';
  62. let payType = await $.getJSON('mobile_order/pay_type');
  63. let mobileRules = await $.getJSON('mobile/mobile_rules');
  64. table.on('load-success.bs.table', function (_, data) {
  65. let e=data.extend;
  66. $('#orderAmount').html(`收入:${e.total},支付宝:${e.alipay},微信:${e.wechat},抖音:${e.dy},快手:${e.ks},成本:${e.di},利润:${e.profit},退款:${e.refund}`)
  67. });
  68. $(document).on('click','.btn-click-show-open',function (){
  69. if($(this).data('open')!==1){
  70. parent.layer.msg('该用户未上传开卡资料')
  71. return
  72. }
  73. Fast.api.open($.fn.bootstrapTable.defaults.extend.show_open_data_url+'/id/'+$(this).data('id'),'查看资料',{
  74. shade:.3,
  75. shadeClose:false,
  76. })
  77. })
  78. $(document).on('click','.btn-sub-remark',function (){
  79. let id=$(this).data('id')
  80. let url=table.data('url-sub-remark')+`/id/${id}`
  81. Fast.api.open(url,'备注')
  82. })
  83. let columns=[
  84. //{checkbox: true},
  85. {field: 'id', title: __('ID'),operate:false,},
  86. {field: 'order_no', title: __('订单号'),visible:false,operate: 'like'},
  87. {field: 'pay_no', title: __('支付单号'),visible: false,operate: '='},
  88. {field: 's_id', title: __('来源渠道'),formatter(_, order) {
  89. let a=[]
  90. a.push(`<div>${order.s_id}</div>`);
  91. a.push(`<div>${order.s_name}</div>`);
  92. return a.join('')
  93. }},
  94. // {field: 'anchor.name', title:__('主播名称') ,searchList(){return Template('anchor-sub-search',{});},width: 100},
  95. {field: 'pay_type', title: __('支付方式'),searchList: payType,visible: false, operate: is_proxy_operate},
  96. {field: 'no', title: __('手机号'),visible: false,operate: 'LIKE'},
  97. {field: 'phone', title: __('收货人手机'),visible: false,operate: 'LIKE'},
  98. {field: 'name', title: __('收货人'),visible: false,operate: 'LIKE'},
  99. {field: 'id_no', title: __('收货人身份证'),visible: false,operate: "like"},
  100. {field: 'pay_mid_wechat', title: __('微信商户号'),visible: false, operate: is_proxy_operate},
  101. {field: 'pay_mid_alipay', title: __('支付宝商户号'),visible: false,operate: is_proxy_operate},
  102. {field: 'pay_mid_dy', title: __('抖音商户号'),visible: false,operate: is_proxy_operate},
  103. {field: 'pay_mid_ks', title: __('快手商户号'),visible: false,operate: is_proxy_operate},
  104. {field: 'order_no', title: __('订单信息'),operate: false,formatter(_,order){
  105. let a=[]
  106. a.push(`<div>订单号:<b class="btn-order_link" data-link="${order.order_no}">${order.order_no}</b></div>`)
  107. if(order.pay_no){
  108. a.push(`<div>支付单号:<b class="btn-order_link" data-link="${order.pay_no}">${order.pay_no}</b></div>`)
  109. }
  110. a.push(`<div class="btn-order_link" data-link="${order.no}"><b>商品信息:${order.no}</b></div>`)
  111. a.push(`<div>归属地:${order.info.mobile.province}/${order.info.mobile.city}</div>`)
  112. if(adminInfo.is_manager){
  113. a.push(`<div>供应商:${order.proxy?order.proxy.nickname:''}</div>`)
  114. }
  115. a.push(`<div>运营商:${order.info?order.info.mobile.network:''}</div>`)
  116. a.push(`<div>卡品牌:${order.brand}</div>`)
  117. if(showAmountDi && is_proxy==0) {
  118. a.push(`<div class="btn-order_link" data-link="${order}">底价:${order.amount_di}</div>`)
  119. }
  120. a.push(`<div class="btn-order_link" data-link="${order.amount_charge}">预存:${order.amount_charge}</div>`)
  121. if(is_proxy == 0 ) {
  122. a.push(`<div class="btn-order_link" data-link="${order.info.mobile.is_activity?order.info.mobile.amount_kill:order.info.mobile.amount_base}"><b>售价:${order.info.mobile.is_activity?order.info.mobile.amount_kill:order.info.mobile.amount_base}</b></div>`)
  123. a.push(`<div class="btn-order_link" data-link="${order.amount}">订单价格:${order.amount}</div>`)
  124. }
  125. a.push(`<div class='btn-order_link' data-link="${order.info.info.describe}">套餐:${order.info?order.info.info.describe:''}</div>`)
  126. a.push(`<div>备注:${order.info?order.info.mobile.remark:''}</div>`)
  127. // a.push(`<a class="btn btn-success btn-sm btn-order_link" data-link="${a.join('')}">点击复制</a>`)
  128. return `<div style="max-width: 250px;word-wrap: break-word;word-break: break-all;white-space: normal;text-align: left;">${a.join('')}</div>`
  129. },width:250,valign:'top',align:'left'},
  130. {field: 'order_no', title: __('收货人'),operate: false,formatter(_,order){
  131. let a=[]
  132. a.push(`<div class="btn-order_link" data-link="${order.name}">收货人:${order.name}</div>`)
  133. a.push(`<div class="btn-order_link" data-link="${order.phone}">手机号:${order.phone}<span style="color: red;">(${order.phone_order_count})</span></div>`)
  134. a.push(`<div class="btn-order_link" data-link="${order.address}">地址:${order.address}</div>`)
  135. if(is_proxy == 0 ) {
  136. a.push(`<div>支付方式:${payType[order.pay_type]}</div>`)
  137. a.push(`<div>微信商户号:<span style="color: #00b578;">${order.pay_mid_wechat}</span></div>`)
  138. a.push(`<div>支付宝商户号:<span style="color: #0d6aad;">${order.pay_mid_alipay}</span></div>`)
  139. a.push(`<div>抖音商户号:<span style="color: #0d6aad;">${order.pay_mid_dy}</span></div>`)
  140. a.push(`<div>快手商户号:<span style="color: #0d6aad;">${order.pay_mid_ks}</span></div>`)
  141. }
  142. a.push(`<div>备注:${order.remark}</div>`)
  143. a.push(`<div>快递名称:${order.trans_name}</div>`)
  144. a.push(`<div>快递单号:${order.trans_no}</div>`)
  145. a.push(`<a class="btn btn-link btn-click-show-open" style="color: #00a2ff;" data-id="${order.id}" data-open="${order.open_uploaded}">查看资料</a>`)
  146. return `<div style="max-width: 200px;text-align: left;" class="break-words">${a.join('')}</div>`
  147. },width:200,valign:'top',align:'left'},
  148. {field: 'status', title: __('Status'),formatter(a,order){
  149. if(a===30) {
  150. return `<span class="label label-primary">${status[order.status_bak]||''}-${status[a]}</span>`
  151. }
  152. if(`${status[a]}` == '待付款'){
  153. return `<span class="label ${statusColor[a]}" style="background-color: green">${status[a]}</span>`
  154. }
  155. if(`${status[a]}` == '已完成'){
  156. return `<span class="label ${statusColor[a]}" style="background-color: RGB(243,156,18)">${status[a]}</span>`
  157. }
  158. return `<span class="label ${statusColor[a]}">${status[a]}</span>`
  159. },searchList:status,operate: is_proxy_operate_eq},
  160. {field: 'platform_source', title: __('来源'),operate: is_proxy_operate},
  161. {field: 'anchor.name', title:__('主播名称') ,searchList(){return Template('anchor-search',{});},width: 100},
  162. {field: 'sub_anchor.mobile_anchor.name', title: __(adminInfo.is_sub?'主播名称':'分站主播'),searchList(){return Template('anchor-sub-search',{});},width: 100,operate: is_proxy_operate,visible:is_proxy_operate},
  163. {field: 'rules.rule', title: __('规律'),visible: false,searchList:mobileRules},
  164. {field: '', title: __('退款记录'),formatter(_,order){
  165. let a=[]
  166. order.refund_log.forEach(item=>{
  167. a.push(`<div>${item.create_time_format} ${item.pass?'同意':'驳回'} ${item.reason}</div>`)
  168. })
  169. return `<div style="text-align: left;font-size: 10px;" class="break-words">${a.join('')}</div>`
  170. },operate:false,valign:'top',align:'left',width: 200,visible:is_proxy_operate},
  171. {field: 'sub_log', title: __(adminInfo.is_manager?'分站备注':'备注'),formatter(_,order){
  172. let a=[]
  173. order.sub_remark.forEach(item=>{
  174. a.push(`<div><span style="color: #0000ff;">${item.create_time_format}</span> <span style="color: #00caff">${item.admin?item.admin.nickname:'-'}</span> ${item.content}</div>`)
  175. })
  176. if(table.data('auth-url-sub-remark')) {
  177. a.push(`<a class="btn btn-info btn-xs btn-sub-remark" data-id="${order.id}">备注</a>`)
  178. }
  179. return `<div style="text-align: left;font-size: 10px;max-width: 200px;" class="break-words">${a.join('')}</div>`
  180. },operate:false,valign:'top',align:'left',width:200},
  181. {field: 'operation_log', title: __('客服记录'),formatter(_,order){
  182. let a=[]
  183. order.operation.forEach(item=>{
  184. a.push(`<div><span style="color: #0000ff;">${item.create_time_format}</span> <span style="color: #00caff">${item.admin?item.admin.nickname:'-'}</span> ${item.content}</div>`)
  185. })
  186. return `<div style="text-align: left;font-size: 10px;max-width: 200px;" class="break-words">${a.join('')}</div>`
  187. },operate:false,valign:'top',align:'left',width:200},
  188. {field: 'admin.admin_id', title: __('操作员'),formatter(_,order){
  189. let a=[]
  190. order.admin.forEach(item=>{
  191. a.push(`<div>${item.admin.nickname}</div>`)
  192. })
  193. return `<div style="text-align: left;font-size: 10px;">${a.join('')}</div>`
  194. },operate:"=",searchList: admins,valign:'top',align:'left',width: 100},
  195. {field: 'pay_link', title: __('付款链接'),formatter(_,order){
  196. if(order.status!==0){
  197. return ''
  198. }
  199. return `<button class="btn btn-success btn-sm btn-pay_link" data-link="${order.pay_link}">点击复制</button>`
  200. },operate:false,width: 150,visible:is_proxy_operate},
  201. {field: 'create_time', title: __('Create_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
  202. //{field: 'update_time', title: __('更新时间'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
  203. /* {field: 'pay_time', title: __('Pay_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange',operate: 'range'},
  204. {field: 'trans_name', title: __('Trans_name')},
  205. {field: 'trans_no', title: __('Trans_no')},
  206. {field: 'amount_original', title: __('Amount_original'), operate: 'BETWEEN'},
  207. {field: 'amount_hd', title: __('Amount_hd'), operate: 'BETWEEN'},
  208. {field: 'amount_charge', title: __('Amount_charge'), operate: 'BETWEEN'},
  209. {field: 'amount', title: __('Amount'), operate: 'BETWEEN'},
  210. {field: 'open_idcard_face_img', title: __('开卡身份证正面照'),formatter: Table.api.formatter.image,events: Table.api.events.image,opera: false},
  211. {field: 'open_idcard_back_img', title: __('开卡身份证背面照'),formatter: Table.api.formatter.image,events: Table.api.events.image,operate:false},
  212. {field: 'open_face_img', title: __('开卡人头像'),formatter: Table.api.formatter.image,events: Table.api.events.image,operate:false},
  213. {field: 'open_name', title: __('开卡人姓名')},
  214. {field: 'open_id_no', title: __('开卡人身份证号码')},
  215. {field: 'open_phone', title: __('开卡人手机号')},*/
  216. {field: 'trans_no', title: __('Trans_no'),visible: false,operate: "like"},
  217. {
  218. field: 'operate',
  219. title: __('Operate'),
  220. table: table,
  221. events: Table.api.events.buttons,
  222. formatter: Table.api.formatter.buttons,
  223. buttons:[
  224. {
  225. name: 'detail',
  226. text: __('设置主播'),
  227. title: __('设置主播'),
  228. classname: 'btn btn-xs btn-info btn-dialog period',
  229. url: table.data('url-set_anchor'),
  230. callback: function (data) {
  231. },
  232. visible: function (row) {
  233. return $('#table').data('auth-set_anchor');
  234. }
  235. },
  236. {
  237. name: 'detail',
  238. text: __('添加备注'),
  239. title: __('添加备注'),
  240. classname: 'btn btn-xs btn-info btn-dialog period',
  241. url: 'mobile_order/add_operation?a=1',
  242. callback: function (data) {
  243. },
  244. visible: function (row) {
  245. return $('#table').data('add_operation');
  246. }
  247. },
  248. {
  249. name: 'detail',
  250. text: __('编辑'),
  251. title: __('编辑'),
  252. classname: 'btn btn-xs btn-info btn-dialog period',
  253. url: 'mobile_order/edit?a=1',
  254. callback: function (data) {
  255. },
  256. visible: function (row) {
  257. return $('#table').data('add_operation');
  258. }
  259. },
  260. {
  261. name: 'detail',
  262. text: __('退款'),
  263. title: __('退款'),
  264. classname: 'btn btn-xs btn-danger btn-dialog period',
  265. url: 'mobile_order/refund?a=1',
  266. callback: function (data) {
  267. },
  268. visible: function (row) {
  269. return $('#table').data('mobile_order_refund') && row.status>0 && row.status!=90;
  270. }
  271. },
  272. {
  273. name: 'detail',
  274. text: __('发货'),
  275. title: __('发货'),
  276. classname: 'btn btn-xs btn-info btn-dialog period',
  277. url: 'mobile_order/send?a=1',
  278. callback: function (data) {
  279. },
  280. visible: function (row) {
  281. return $('#table').data('mobile_order_send') && row.status>0;
  282. }
  283. },
  284. {
  285. name:'detail',
  286. title:'查看物流',
  287. text: __('查看物流'),
  288. classname: 'btn btn-xs btn-danger btn-dialog',
  289. url: 'mobile_order/see_logistics?a=1',
  290. visible:(row)=>{
  291. return $('#table').data('see_logistics') && row.trans_id>0 && row.trans_no
  292. }
  293. },
  294. {
  295. name: 'detail',
  296. text: __('上架'),
  297. title: __('上架'),
  298. classname: 'btn btn-xs btn-success btn-dialog period',
  299. url: 'mobile_order/mobile_up?a=1',
  300. callback: function (data) {
  301. if(data && data.say){
  302. parent.layer.alert(data.say)
  303. }
  304. },
  305. visible: function (row) {
  306. return $('#table').data('auth-mobile_up') && [90].indexOf(row.status)>-1;
  307. },
  308. disable(row){
  309. return row.mobile_can_up
  310. }
  311. },
  312. {
  313. name: 'detail',
  314. text: __('抖音结算'),
  315. title: __('抖音结算'),
  316. classname: 'btn btn-xs btn-success btn-ajax',
  317. url: 'mobile_order/dy_settle',
  318. confirm:'确认结算吗?',
  319. callback: function (data) {
  320. },
  321. visible: function (row) {
  322. return $('#table').data('auth-dy_settle') && row.pay_type===4 && row.pay_time>0 && row.payment && row.payment.settle_status===0;
  323. },
  324. disable(row){
  325. }
  326. },
  327. ]
  328. }
  329. ]
  330. if(!adminInfo.is_manager){
  331. Table.api.removeColumn('operation_log',columns)
  332. Table.api.removeColumn('anchor.name',columns)
  333. Table.api.removeColumn('s_id',columns)
  334. Table.api.removeColumn('admin.admin_id',columns)
  335. }
  336. // 初始化表格
  337. table.bootstrapTable({
  338. url: $.fn.bootstrapTable.defaults.extend.index_url,
  339. pk: 'id',
  340. sortName: 'id',
  341. search:false,
  342. searchFormVisible:true,
  343. columns: [
  344. columns
  345. ],
  346. fixedColumns:true,
  347. fixedRightNumber:1,
  348. onLoadSuccess(a){
  349. $('.btn-export').attr('href',a.link).show()
  350. // 角标
  351. let arr1 = [];let status_all=0;
  352. a.status_list.forEach(function(item, index) {
  353. $(".nav li .nav_id_"+item.status).text(item.total);
  354. arr1.push(item.status);
  355. status_all = status_all+item.total;
  356. });
  357. // 全部
  358. $(".nav li .nav_id_all").text(status_all);
  359. // 无数据的置0
  360. let arr2 = [0,10,15,17,20,25,30,50,60,70,80,90];
  361. let diff=arr2.filter(item=>arr1.indexOf(item)==-1);
  362. diff.forEach(function (i,k){
  363. $(".nav li .nav_id_"+i).text(0);
  364. });
  365. $(".nav li .nav_id_10").text(a.status_10_count);
  366. /*table.find('thead').css('position','fixed').css('background','white').css('top','370px')
  367. table.css('margin-top',41)
  368. table.find('tbody>tr:first-child>td').each((a,b)=>{
  369. table.find('thead tr th').eq(a).css('width',b.offsetWidth).css('max-width',b.offsetWidth)
  370. })*/
  371. }
  372. });
  373. // 为表格绑定事件
  374. Table.api.bindevent(table);
  375. /* let innerHeight=window.innerHeight
  376. $('.fixed-table-container').css('height',`${innerHeight-420}px`)
  377. window.addEventListener('resize',function (){
  378. let innerHeight=window.innerHeight
  379. $('.fixed-table-container').css('height',`${innerHeight-420}px`)
  380. })*/
  381. },
  382. add: function () {
  383. Controller.api.bindevent();
  384. },
  385. edit: function () {
  386. Controller.api.bindevent();
  387. $(document).on('input propertychange','#c-trans_no',function (){
  388. let no=$(this).val()
  389. if(!no){
  390. return
  391. }
  392. Form.api.guessLogistics(no,'#c-trans_id')
  393. })
  394. },
  395. add_operation(){
  396. Controller.api.bindevent();
  397. $('#c-no').focus()
  398. },
  399. sub_remark(){
  400. Controller.api.bindevent();
  401. $('#c-no').focus()
  402. },
  403. set_anchor(){
  404. Controller.api.bindevent();
  405. },
  406. refund(){
  407. Controller.api.bindevent();
  408. },
  409. mobile_up(){
  410. Controller.api.bindevent()
  411. if(!row){
  412. Fast.api.close({say:'此号码已被删除,无法上架'})
  413. }else if(row.status===0){
  414. //Fast.api.close({say:'此号码已是上架状态'})
  415. }
  416. },
  417. send(){
  418. Controller.api.bindevent();
  419. $(document).on('input propertychange','#c-trans_no',function (){
  420. let no=$(this).val()
  421. if(!no){
  422. return
  423. }
  424. Form.api.guessLogistics(no,'#c-trans_id')
  425. })
  426. },
  427. show_open_data(){
  428. Controller.api.bindevent()
  429. },
  430. api: {
  431. bindevent: function () {
  432. Form.api.bindevent($("form[role=form]"));
  433. }
  434. },
  435. refund_log(){
  436. Table.api.init();
  437. var table = $("#table");
  438. let columns=[
  439. //{field:'id',title:'ID',operate:false},
  440. {field:'od.mobile_id',title:'商品ID',operate:'='},
  441. {field:'od.s_id',title:'代理商ID',operate:'='},
  442. {field:'od.order_no',title:'订单号',operate:'='},
  443. {field:'od.no',title:'手机号',operate:'like'},
  444. {field:'pass',title:'审核状态',searchList:{1:'通过',0:'驳回'},formatter: Table.api.formatter.label},
  445. {field:'reason',title:'备注',formatter: Table.api.formatter.content,width:200},
  446. {field:'od.amount',title:'订单金额',operate:'between'},
  447. {field:'amount_backend',title:'退款金额',operate:'between'},
  448. {field:'create_time',title:'创建时间',operate:'range',addClass:'datetimerange',formatter:Table.api.formatter.datetime},
  449. {field:'admin.nickname',title:' 操作员',operate:'like'},
  450. ];
  451. if(!admin.is_manager){
  452. Table.api.removeColumn('od.s_id',columns)
  453. }
  454. table.bootstrapTable({
  455. url: 'mobile_order/refund_log',
  456. pk: 'id',
  457. sortName: 'id',
  458. search:false,
  459. searchFormVisible:true,
  460. columns: columns,
  461. onLoadSuccess(a){
  462. }
  463. });
  464. Table.api.bindevent(table);
  465. }
  466. };
  467. return Controller;
  468. });