eachGiftInfor.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // pages/eachGiftInfor/eachGiftInfor.js
  2. // pages/awaitState/awaitState.js
  3. var app = getApp()
  4. Page({
  5. data: {
  6. src: '',
  7. msg: '',
  8. url: '',
  9. name: '',
  10. order_userid: '',
  11. sendUserId: '',
  12. recHidden: false,
  13. sendHidden: false,
  14. time: '',
  15. uploadImg: [],
  16. newImgList: [],
  17. order_type: '0',
  18. goodsList: [],
  19. showSendFriendMsg: false,//送朋友弹窗
  20. goodsId: 0, //送朋友-当前商品在列表中的id
  21. linkFlag: -1,
  22. shareTime: '',
  23. footerHidden: true, //默认底部按钮隐藏
  24. authorize: 0, //授权标志位
  25. userInfo: {},//用户信息
  26. from_user_id:'',//送礼物者union_id
  27. order_number: '',//订单号
  28. infor:{},
  29. listId:'',
  30. from_user_name:'',
  31. order_num_o: '',//原始单
  32. orderNumber: '',//拆分单
  33. orderNumberGift: '',//分享单号
  34. },
  35. onLoad: function (options) {
  36. var that = this;
  37. var host = getApp().globalData.servsers;
  38. var un_id = getApp().globalData.un_id;
  39. var order_num_o = options.order_num_o;//原始单
  40. var orderNumber = options.orderNumber;//拆分单
  41. var orderNumberGift = options.orderNumberGift;//分享单号
  42. var from_user_id = options.from_user_id;
  43. var shareTime = options.shareTime;
  44. var sta = options.sta;
  45. var listId = options.listId;
  46. console.log(options.infor);
  47. var infor = options.infor;
  48. // $nickname = preg_replace('/[\x{1F600}-\x{1F64F}]/u', '', $nickname);
  49. // $nickname = preg_replace('/[\x{1F300}-\x{1F5FF}]/u', '', $nickname);
  50. // $nickname = preg_replace('/[\x{1F680}-\x{1F6FF}]/u', '', $nickname);
  51. // $nickname = preg_replace('/[\x{2600}-\x{26FF}]/u', '', $nickname);
  52. // $nickname = preg_replace('/[\x{2700}-\x{27BF}]/u', '', $nickname);
  53. // $nickname = str_replace(array('"', '\''), '', $nickname);
  54. // $nickname = addslashes(trim($nickname));
  55. //infor = infor.replace(/zss/g, "&");
  56. infor = JSON.parse(infor);
  57. console.log(infor);
  58. that.setData({
  59. from_user_id: from_user_id,
  60. order_num_o: order_num_o,
  61. orderNumber: orderNumber,
  62. orderNumberGift: orderNumberGift,
  63. sta: sta,
  64. listId: listId,
  65. infor: infor,
  66. src: infor.giftImg,
  67. goodsName: infor.affList[0].com_name,
  68. goodsNum: infor.affList[0].com_num,
  69. url: infor.fromUserHead,
  70. name: infor.fromUserName,
  71. msg: infor.giftMsg,
  72. newImgList: infor.imgList,
  73. order_userid: options.order_userid,//送礼物者的union_id
  74. })
  75. console.log("sta:" + sta);
  76. console.log("order_type:" + that.data.order_type);
  77. console.log("order_num_o:" + order_num_o);
  78. console.log("orderNumber:" + orderNumber);
  79. console.log("orderNumberGift:" + orderNumberGift);
  80. console.log("from_user_id:" + from_user_id);
  81. console.log(infor);
  82. if (un_id != undefined && un_id != '' && un_id != null){
  83. //查询订单状态
  84. wx.request({
  85. url: host + "orderapi/findOrderTypeByOrderNumber",
  86. data: {
  87. order_number: orderNumber
  88. },
  89. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  90. header: {
  91. 'Accept': 'application/json'
  92. },
  93. success: function (res) {
  94. that.setData({
  95. order_type: res.data
  96. })
  97. console.log("order_type2:"+res.data);
  98. if (res.data != 2) {//朋友未完全收下礼物【可能转送了】
  99. console.log("shareTime:" + shareTime);
  100. //查询同一分享链接,礼物接收状态【根据订单号和时间做唯一标识,0为未被接收,1为被接收】
  101. wx.request({
  102. url: host + "orderapi/findlinkByOrderNumber",
  103. data: {
  104. order_number: orderNumber,
  105. order_timeno: shareTime
  106. },
  107. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  108. header: {
  109. 'Accept': 'application/json'
  110. },
  111. success: function (res) {
  112. console.log("linkFlag:"+res.data);
  113. that.setData({
  114. linkFlag: res.data,
  115. footerHidden: false
  116. })
  117. }
  118. })
  119. }
  120. if (res == null || res.data == null) {
  121. console.error('网络请求失败');
  122. return;
  123. }
  124. }
  125. });
  126. }
  127. },
  128. addGiftList: function (e) {
  129. var that = this;
  130. var host = getApp().globalData.servsers;
  131. var un_id = getApp().globalData.un_id;
  132. var openid = getApp().globalData.openid;
  133. var order_number = that.data.order_number;
  134. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  135. wx.navigateTo({
  136. url: '/pages/authorize/authorize?link=awaitState',
  137. })
  138. } else {
  139. //更改当前链接下,接收礼物的状态为1
  140. wx.request({
  141. url: host + "orderapi/updateOrder_link",
  142. data: {
  143. order_number: that.data.orderNumber,
  144. order_timeno: that.data.shareTime,
  145. order_linkFlag: 1
  146. },
  147. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  148. header: {
  149. 'Accept': 'application/json'
  150. },
  151. success: function (res) {
  152. //修改送礼物 - 接收状态为1【已接收】
  153. wx.request({
  154. url: host + "orderapi/updateOrder_linkFlag",
  155. data: {
  156. order_number: that.data.orderNumber,
  157. linkFlag: 1
  158. },
  159. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  160. header: {
  161. 'Accept': 'application/json'
  162. },
  163. success: function (res) {
  164. if (res == null || res.data == null) {
  165. console.error('网络请求失败');
  166. return;
  167. }
  168. }
  169. });
  170. //对应用户保存收到的礼物
  171. wx.request({
  172. url: host + "giftapi/insertUserGift",
  173. data: {
  174. userId: un_id,
  175. giftImg: that.data.src,
  176. giftMsg: that.data.msg,
  177. fromUserHead: that.data.url,
  178. fromUserName: that.data.name,
  179. orderNumber: that.data.orderNumber,
  180. orderNumberGift: that.data.orderNumberGift,//拆分的订单号
  181. cTime: that.data.time,
  182. giftOtherImg: that.data.uploadImg,
  183. user_head: taht.data.userInfo.avatarUrl,//收礼物者头像
  184. user_name: taht.data.userInfo.nickName,//收礼物者微信名
  185. from_user_id: that.data.order_userid,//送礼物者union_id
  186. receive_flag: 0 //礼物接收状态
  187. },
  188. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  189. header: {
  190. 'Accept': 'application/json'
  191. },
  192. success: function (res) {
  193. console.log("接收礼物成功!");
  194. //更改"送礼物表"标志位
  195. wx.request({
  196. url: host + "giftapi/updateReceive_flag_send",
  197. data: {
  198. order_number: that.data.orderNumber,
  199. order_number_gift: that.data.orderNumberGift,
  200. },
  201. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  202. header: {
  203. 'Accept': 'application/json'
  204. },
  205. success: function (res) {
  206. var preFlag = that.data.flag;
  207. // if (preFlag == '1') {//来自礼物详情页【awaitState】
  208. // wx.navigateTo({
  209. // url: '/pages/mineGiftList/mineGiftList?isSelectNew=1',
  210. // })
  211. // } else {
  212. // wx.navigateBack({
  213. // delta: 1
  214. // })
  215. // }
  216. wx.navigateTo({
  217. url: '/pages/mineGiftList/mineGiftList?isSelectNew=1',
  218. })
  219. if (res == null || res.data == null) {
  220. console.error('网络请求失败');
  221. return;
  222. }
  223. }
  224. });
  225. if (res == null || res.data == null) {
  226. console.error('网络请求失败');
  227. return;
  228. }
  229. }
  230. });
  231. }
  232. })
  233. }
  234. },
  235. onShow: function () {
  236. var that = this;
  237. var authorize = that.data.authorize;
  238. var un_id = getApp().globalData.un_id;
  239. if (authorize == 1) {//调起授权,并且授权成功
  240. //直接执行放入礼物盒操作
  241. //that.addGiftList();
  242. }
  243. if (un_id != undefined && un_id != '' && un_id != null) {
  244. that.setData({
  245. userInfo: getApp().globalData.userInfo,
  246. })
  247. console.log("un_id::" + un_id);
  248. }
  249. },
  250. selectWuliu: function () {
  251. var that = this;
  252. wx.navigateTo({
  253. url: '/pages/wuliu/wuliu?id=' + that.data.order_number,
  254. success: function (res) { },
  255. fail: function (res) { },
  256. complete: function (res) { },
  257. })
  258. },
  259. wantSent: function (e) {
  260. wx.switchTab({
  261. url: '/pages/index/index'
  262. })
  263. },
  264. previewImg: function (e) {//banner图预览
  265. var that = this;
  266. var currentUrl = e.currentTarget.dataset.src;
  267. wx.previewImage({
  268. current: currentUrl,
  269. urls: that.data.uploadImg.imgList
  270. })
  271. },
  272. getGift: function () {//领取礼物
  273. var that = this;
  274. var host = getApp().globalData.servsers;
  275. var order_number = that.data.order_number;
  276. wx.navigateTo({
  277. url: '/pages/addAddressFriend/addAddressFriend?order_number=' + order_number
  278. })
  279. },
  280. sendBtn: function (e) {//送朋友 - 提示弹窗
  281. var that = this;
  282. var id = e.currentTarget.dataset.id;//i
  283. that.setData({
  284. showSendFriendMsg: true
  285. })
  286. },
  287. sureSendFriend: function (options) {//送朋友 - 确定
  288. var that = this;
  289. var order_number = that.data.order_number;
  290. var imgSrc = that.data.goodsList.affList[0].logo;
  291. var goodsList = that.data.goodsList;
  292. var newCarts = JSON.stringify(that.data.goodsList);
  293. newCarts = newCarts.replace(/&/g, "zss");
  294. that.setData({
  295. showSendFriendMsg: false
  296. })
  297. setTimeout(function () {
  298. wx.navigateTo({
  299. url: '/pages/share/share?src=' + imgSrc + "&id=" + goodsList.affList[0].com_id + '&order_number=' + goodsList.order.order_number + '&order_userid=' + goodsList.order.order_userid + "&goodsNme=" + goodsList.affList[0].com_name + "&goodsNum=" + goodsList.affList[0].com_num + "&goodsList=" + newCarts + "&flag=1",
  300. success: function (res) {
  301. }
  302. })
  303. }, 500)
  304. },
  305. cancelSendFriend: function (e) {//送朋友 - 取消
  306. var that = this;
  307. that.setData({
  308. goodsId: '',
  309. showSendFriendMsg: false
  310. })
  311. },
  312. })