截流自动化的商城平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

BargainLaunch.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model\bargain;
  20. use app\common\basics\Models;
  21. use app\common\model\user\User;
  22. use app\common\model\order\Order;
  23. use app\common\server\UrlServer;
  24. /**
  25. * 砍价活动 参与模型
  26. * Class BargainLaunch
  27. * @Author 张无忌
  28. * @package app\common\model
  29. */
  30. class BargainLaunch extends Models
  31. {
  32. protected $json = ['goods_snap', 'bargain_snap'];
  33. protected $jsonAssoc = true;
  34. const conductStatus = 0; //进行中
  35. const successStatus = 1; //成功
  36. const failStatus = 2; //失败
  37. /**
  38. * @notes 砍价状态描述
  39. * @param bool $type
  40. * @return string|string[]
  41. * @author suny
  42. * @date 2021/7/13 6:41 下午
  43. */
  44. public static function getStatusDesc($type = true)
  45. {
  46. $desc = [
  47. self::conductStatus => '砍价中',
  48. self::successStatus => '砍价成功',
  49. self::failStatus => '砍价失败',
  50. ];
  51. if ($type === true) {
  52. return $desc;
  53. }
  54. return $desc[$type] ?? '未知';
  55. }
  56. /**
  57. * @notes 关联用户模型
  58. * @return \think\model\relation\HasOne
  59. * @author suny
  60. * @date 2021/7/13 6:41 下午
  61. */
  62. public function user()
  63. {
  64. return $this->hasOne(user::class, 'id', 'user_id')
  65. ->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
  66. }
  67. /**
  68. * @notes 关联订单模型
  69. * @return BargainLaunch|\think\model\relation\HasOne
  70. * @author suny
  71. * @date 2021/7/13 6:41 下午
  72. */
  73. public function order()
  74. {
  75. return $this->hasOne(Order::class, 'id', 'order_id')
  76. ->field('id,order_sn,user_id,create_time,order_amount,order_status');
  77. }
  78. /**
  79. * @notes 关联砍价助力bargain_knife
  80. * @return \think\model\relation\HasMany
  81. * @author suny
  82. * @date 2021/7/13 6:41 下午
  83. */
  84. public function bargainKnife()
  85. {
  86. return $this->hasMany('bargain_knife', 'launch_id', 'id');
  87. }
  88. /**
  89. * @notes 显示商品价格
  90. * @param $value
  91. * @param $data
  92. * @return mixed
  93. * @author suny
  94. * @date 2021/7/13 6:41 下午
  95. */
  96. public function getPriceAttr($value, $data)
  97. {
  98. return $data['goods_snap']['price'];
  99. }
  100. // //显示用户头像
  101. // public function getAvatarAttr($value,$data){
  102. // return UrlServer::getFileUrl($data['user']['avatar']);
  103. // }
  104. /**
  105. * @notes 显示商品主图
  106. * @param $value
  107. * @param $data
  108. * @return string
  109. * @author suny
  110. * @date 2021/7/13 6:41 下午
  111. */
  112. public function getGoodsImageAttr($value, $data)
  113. {
  114. return UrlServer::getFileUrl($data['goods_snap']['goods_iamge']);
  115. }
  116. /**
  117. * @notes 显示商品名称
  118. * @param $value
  119. * @param $data
  120. * @return mixed
  121. * @author suny
  122. * @date 2021/7/13 6:42 下午
  123. */
  124. public function getNameAttr($value, $data)
  125. {
  126. return $data['goods_snap']['name'];
  127. }
  128. /**
  129. * @notes 显示商品规格ID
  130. * @param $value
  131. * @param $data
  132. * @return mixed
  133. * @author suny
  134. * @date 2021/7/13 6:42 下午
  135. */
  136. public function getItemIdAttr($value, $data)
  137. {
  138. return $data['goods_snap']['item_id'];
  139. }
  140. /**
  141. * @notes 显示规格名称
  142. * @param $value
  143. * @param $data
  144. * @return mixed
  145. * @author suny
  146. * @date 2021/7/13 6:42 下午
  147. */
  148. public function getSpecValueStrAttr($value, $data)
  149. {
  150. return $data['goods_snap']['spec_value_str'];
  151. }
  152. /**
  153. * @notes 砍价按钮
  154. * @param $value
  155. * @param $data
  156. * @return string
  157. * @author suny
  158. * @date 2021/7/13 6:42 下午
  159. */
  160. public function getBtnTipsAttr($value, $data)
  161. {
  162. $tips = '';
  163. if (1 == $data['status']) {
  164. $tips = '砍价成功';
  165. } else if (0 == $data['status']) {
  166. $tips = '继续砍价';
  167. }
  168. return $tips;
  169. }
  170. // //显示直接购买按钮
  171. // public function getBuyBtnAttr($value,$data){
  172. // $btn = 0;
  173. // if(2 == $data['bargain_snap']['payment_where'] && empty($data['order_id'])){
  174. // $btn = 1;
  175. // }
  176. // return $btn;
  177. // }
  178. /**
  179. * @notes 显示查看订单按钮
  180. * @param $value
  181. * @param $data
  182. * @return int
  183. * @author suny
  184. * @date 2021/7/13 6:42 下午
  185. */
  186. public function getOrderBtnAttr($value, $data)
  187. {
  188. $btn = 0;
  189. if ($data['order_id']) {
  190. $btn = 1;
  191. }
  192. return $btn;
  193. }
  194. /**
  195. * @notes 继续砍价按钮
  196. * @param $value
  197. * @param $data
  198. * @return int
  199. * @author suny
  200. * @date 2021/7/13 6:42 下午
  201. */
  202. public function getBargainBtnAttr($value, $data)
  203. {
  204. $btn = 0;
  205. if (0 == $data['status']) {
  206. $btn = 1;
  207. }
  208. return $btn;
  209. }
  210. /**
  211. * @notes 砍价成功按钮
  212. * @param $value
  213. * @param $data
  214. * @return int
  215. * @author suny
  216. * @date 2021/7/13 6:42 下午
  217. */
  218. public function getSuccessBtnAttr($value, $data)
  219. {
  220. $btn = 0;
  221. if (1 == $data['status']) {
  222. $btn = 1;
  223. }
  224. return $btn;
  225. }
  226. /**
  227. * @notes 显示去支付按钮
  228. * @param $value
  229. * @param $data
  230. * @return int
  231. * @author suny
  232. * @date 2021/7/13 6:43 下午
  233. */
  234. public function getPayBtnAttr($value, $data)
  235. {
  236. $btn = 0;
  237. if (1 == $data['status']) {
  238. $btn = 1;
  239. }
  240. return $btn;
  241. }
  242. /**
  243. * @notes 显示砍价提示
  244. * @param $value
  245. * @param $data
  246. * @return string
  247. * @author suny
  248. * @date 2021/7/13 6:43 下午
  249. */
  250. public function getBargainTipsAttr($value, $data)
  251. {
  252. $tips = '须砍至最低价才可支付购买';
  253. if (2 == $data['bargain_snap']['payment_where']) {
  254. $tips = '砍至任意金额可直接购买';
  255. }
  256. return $tips;
  257. }
  258. /**
  259. * @notes 显示状态
  260. * @param $value
  261. * @param $data
  262. * @return string|string[]
  263. * @author suny
  264. * @date 2021/7/13 6:43 下午
  265. */
  266. public function getStatusTextAttr($value, $data)
  267. {
  268. return static::getStatusDesc($data['status']);
  269. }
  270. /**
  271. * @notes 发起砍价时间
  272. * @param $value
  273. * @param $data
  274. * @return false|string
  275. * @author suny
  276. * @date 2021/7/13 6:43 下午
  277. */
  278. public function getCreateTimeAttr($value, $data)
  279. {
  280. return date('Y-m-d H:i:s', $data['launch_start_time']);
  281. }
  282. /**
  283. * @notes 砍价结束时间
  284. * @param $value
  285. * @param $data
  286. * @return mixed
  287. * @author suny
  288. * @date 2021/7/13 6:43 下午
  289. */
  290. public function getOverTimeAttr($value, $data)
  291. {
  292. return $data['launch_end_time'];
  293. }
  294. /**
  295. * @notes 剩余的差价
  296. * @param $value
  297. * @param $data
  298. * @return float
  299. * @author suny
  300. * @date 2021/7/13 6:43 下午
  301. */
  302. public function getDiffPriceAttr($value, $data)
  303. {
  304. return round($data['current_price'] - $data['bargain_price'], 2);
  305. }
  306. /**
  307. * @notes 已砍价的价格
  308. * @param $value
  309. * @param $data
  310. * @return float
  311. * @author suny
  312. * @date 2021/7/13 6:43 下午
  313. */
  314. public function getKnifePriceAttr($value, $data)
  315. {
  316. return round($data['goods_snap']['price'] - $data['current_price'], 2);
  317. }
  318. /**
  319. * @notes 砍价进度条
  320. * @param $value
  321. * @param $data
  322. * @return float
  323. * @author suny
  324. * @date 2021/7/13 6:43 下午
  325. */
  326. public function getProgressAttr($value, $data)
  327. {
  328. if ($data['current_price'] == 0) {
  329. return round(1, 2);
  330. } else {
  331. return round($data['bargain_price'] / $data['current_price'], 2);
  332. }
  333. }
  334. /**
  335. * @notes 活动价
  336. * @param $value
  337. * @param $data
  338. * @return mixed
  339. * @author suny
  340. * @date 2021/7/13 6:43 下午
  341. */
  342. public function getActivityPriceAttr($value, $data)
  343. {
  344. return $data['bargain_snap']['floor_price'];
  345. }
  346. /**
  347. * @notes 显示砍价状态提示
  348. * @param $value
  349. * @param $data
  350. * @return string
  351. * @author suny
  352. * @date 2021/7/13 6:43 下午
  353. */
  354. public function getStatusTipsAttr($value, $data)
  355. {
  356. if (2 == $data['status']) {
  357. return '非常遗憾,砍价失败了';
  358. }
  359. if (1 == $data['status']) {
  360. return '恭喜您,砍价成功';
  361. }
  362. return '';
  363. }
  364. /**
  365. * @notes 显示用户信息
  366. * @param $value
  367. * @param $data
  368. * @return array
  369. * @author suny
  370. * @date 2021/7/13 6:44 下午
  371. */
  372. public function getKnifeListAttr($value, $data)
  373. {
  374. $list = [];
  375. foreach ($this->bargain_knife as $knife) {
  376. $list[] = [
  377. 'id' => $knife['id'],
  378. 'user_id' => $knife['user']['id'],
  379. 'nickname' => $knife['user']['nickname'],
  380. 'avatar' => UrlServer::getFileUrl($knife['user']['avatar']),
  381. 'help_price' => $knife['help_price'],
  382. 'help_time' => date('Y-m-d H:i:s', $knife['help_time']),
  383. ];
  384. }
  385. return $list;
  386. }
  387. /**
  388. * @notes 分享标题
  389. * @param $value
  390. * @param $data
  391. * @return mixed
  392. * @author suny
  393. * @date 2021/7/13 6:44 下午
  394. */
  395. public function getShareTitlesAttr($value, $data)
  396. {
  397. return $data['bargain_snap']['share_title'];
  398. }
  399. /**
  400. * @notes 分享简介
  401. * @param $value
  402. * @param $data
  403. * @return mixed
  404. * @author suny
  405. * @date 2021/7/13 6:44 下午
  406. */
  407. public function getShareIntrosAttr($value, $data)
  408. {
  409. return $data['bargain_snap']['share_intro'];
  410. }
  411. }