StoreStats.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 店铺统计信息表 Table<ai_allwin_store_stats>
  7. */
  8. namespace app\allwin\model;
  9. use think\Model;
  10. class StoreStats extends Model
  11. {
  12. protected $pk = 'id';
  13. protected $table = 'ai_allwin_store_stats';
  14. /**
  15. * 消费收入
  16. * @param array $store 店铺信息
  17. * @param integer $uid
  18. * @param integer $money(元)
  19. * @return void
  20. */
  21. public function payment($store,float $money){
  22. $info = self::where(['store_id' => $store->id])->find();
  23. if (empty($info)) {
  24. $data['member_miniapp_id'] = $store->member_miniapp_id;
  25. $data['store_id'] = $store->id;
  26. $data['payment'] = $money;
  27. return self::create($data);
  28. } else {
  29. $info->payment = ['inc',$money];
  30. return $info->save();
  31. }
  32. }
  33. /**
  34. * 优惠券优惠
  35. * @param integer $miniapp_id
  36. * @param integer $uid
  37. * @param integer $due_money(元)
  38. * @return void
  39. */
  40. public function coupon($store,float $money){
  41. $info = self::where(['store_id' => $store->id])->find();
  42. if (empty($info)) {
  43. $data['member_miniapp_id'] = $store->member_miniapp_id;
  44. $data['store_id'] = $store->id;
  45. $data['coupon'] = $money;
  46. return self::insert($data);
  47. } else {
  48. $info->coupon = ['inc',$money];
  49. return $info->save();
  50. }
  51. }
  52. /**
  53. * 预储会员卡
  54. * @param integer $miniapp_id
  55. * @param integer $uid
  56. * @param integer $due_money(元)
  57. * @return void
  58. */
  59. public function card(int $miniapp_id, int $store_id, float $money)
  60. {
  61. $info = self::get(['store_id' => $store_id]);
  62. if (empty($info)) {
  63. $data['member_miniapp_id'] = $miniapp_id;
  64. $data['store_id'] = $store_id;
  65. $data['card'] = $money;
  66. return self::insert($data);
  67. } else {
  68. $info->card = ['inc',$money];
  69. return $info->save();
  70. }
  71. }
  72. /**
  73. * 创客分润
  74. * @param integer $miniapp_id
  75. * @param integer $uid
  76. * @param integer $due_money(元)
  77. * @return void
  78. */
  79. public function vip(int $miniapp_id, int $store_id, float $money)
  80. {
  81. $info = self::get(['store_id' => $store_id]);
  82. if (empty($info)) {
  83. $data['member_miniapp_id'] = $miniapp_id;
  84. $data['store_id'] = $store_id;
  85. $data['vip'] = $money;
  86. return self::insert($data);
  87. } else {
  88. $info->vip = ['inc',$money];
  89. return $info->save();
  90. }
  91. }
  92. }