Storejoinin.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * 店铺入住模型
  4. */
  5. namespace app\common\model;
  6. use think\facade\Db;
  7. /**
  8. * ============================================================================
  9. * DSMall多用户商城
  10. * ============================================================================
  11. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  12. * 网站地址: http://www.csdeshang.com
  13. * ----------------------------------------------------------------------------
  14. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  15. * 不允许对程序代码以任何形式任何目的的再发布。
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Storejoinin extends BaseModel {
  20. public $page_info;
  21. /**
  22. * 读取列表
  23. * @access public
  24. * @author csdeshang
  25. * @param array $condition 条件
  26. * @param int $pagesize 分页
  27. * @param string $order 排序
  28. * @param string $field 字段
  29. * @return array
  30. */
  31. public function getStorejoininList($condition, $pagesize = '', $order = '', $field = '*') {
  32. if($pagesize){
  33. $result = Db::name('storejoinin')->field($field)->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  34. $this->page_info = $result;
  35. return $result->items();
  36. }else{
  37. $result = Db::name('storejoinin')->field($field)->where($condition)->order($order)->select()->toArray();
  38. return $result;
  39. }
  40. }
  41. /**
  42. * 店铺入住数量
  43. * @access public
  44. * @author csdeshang
  45. * @param array $condition 条件
  46. * @return int
  47. */
  48. public function getStorejoininCount($condition) {
  49. return Db::name('storejoinin')->where($condition)->count();
  50. }
  51. /**
  52. * 读取单条记录
  53. * @access public
  54. * @author csdeshang
  55. * @param array $condition 条件
  56. * @return array
  57. */
  58. public function getOneStorejoinin($condition) {
  59. $result = Db::name('storejoinin')->where($condition)->find();
  60. return $result;
  61. }
  62. /**
  63. * 判断是否存在
  64. * @access public
  65. * @author csdeshang
  66. * @param type $condition 条件
  67. * @return boolean
  68. */
  69. public function isStorejoininExist($condition) {
  70. $result = $this->getOneStorejoinin($condition);
  71. if (empty($result)) {
  72. return FALSE;
  73. } else {
  74. return TRUE;
  75. }
  76. }
  77. /**
  78. * 增加
  79. * @access public
  80. * @author csdeshang
  81. * @param type $data 数据
  82. * @return type
  83. */
  84. public function addStorejoinin($data) {
  85. return Db::name('storejoinin')->insert($data);
  86. }
  87. /**
  88. * 更新
  89. * @access public
  90. * @author csdeshang
  91. * @param type $update 数据
  92. * @param type $condition 条件
  93. * @return type
  94. */
  95. public function editStorejoinin($update, $condition) {
  96. return Db::name('storejoinin')->where($condition)->update($update);
  97. }
  98. /**
  99. * 删除
  100. * @access public
  101. * @author csdeshang
  102. * @param type $condition 条件
  103. * @return type
  104. */
  105. public function delStorejoinin($condition) {
  106. return Db::name('storejoinin')->where($condition)->delete();
  107. }
  108. /**
  109. * 充值卡支付
  110. * 如果充值卡足够就单独支付了该订单,如果不足就暂时冻结,等API支付成功了再彻底扣除
  111. */
  112. public function rcbPay($order_info, $input, $buyer_info) {
  113. $available_rcb_amount = floatval($buyer_info['available_rc_balance']);
  114. if ($available_rcb_amount <= 0)
  115. return $order_info;
  116. $predeposit_model = model('predeposit');
  117. $order_amount = round($order_info['paying_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'], 2);
  118. $data_pd = array();
  119. $data_pd['member_id'] = $buyer_info['member_id'];
  120. $data_pd['member_name'] = $buyer_info['member_name'];
  121. $data_pd['amount'] = $order_amount;
  122. $data_pd['order_sn'] = $order_info['pay_sn'];
  123. if ($available_rcb_amount >= $order_amount) {
  124. // 预存款立即支付,订单支付完成
  125. $predeposit_model->changeRcb('storejoinin_pay', $data_pd);
  126. $available_rcb_amount -= $order_amount;
  127. //支付被冻结的充值卡
  128. $rcb_amount = isset($order_info['rcb_amount']) ? floatval($order_info['rcb_amount']) : 0;
  129. if ($rcb_amount > 0) {
  130. $data_pd = array();
  131. $data_pd['member_id'] = $buyer_info['member_id'];
  132. $data_pd['member_name'] = $buyer_info['member_name'];
  133. $data_pd['amount'] = $rcb_amount;
  134. $data_pd['order_sn'] = $order_info['pay_sn'];
  135. $predeposit_model->changeRcb('storejoinin_comb_pay', $data_pd);
  136. }
  137. $store_model=model('store');
  138. $store_model->setStoreOpen($order_info,array('joinin_state'=>STORE_JOIN_STATE_FINAL,'payment_code'=>'predeposit'));
  139. // 订单状态 置为已支付
  140. $order_info['rcb_amount'] = round($order_info['rcb_amount'] + $order_amount, 2);
  141. } else {
  142. //暂冻结预存款,后面还需要 API彻底完成支付
  143. $data_pd['amount'] = $available_rcb_amount;
  144. $predeposit_model->changeRcb('storejoinin_freeze', $data_pd);
  145. //预存款支付金额保存到订单
  146. $data_order = array();
  147. $order_info['rcb_amount'] = $data_order['rcb_amount'] = round($order_info['rcb_amount'] + $available_rcb_amount, 2);
  148. $result = $this->editStorejoinin($data_order, array('member_id' => $order_info['member_id']));
  149. if (!$result) {
  150. throw new \think\Exception('订单更新失败', 10006);
  151. }
  152. }
  153. return $order_info;
  154. }
  155. /**
  156. * 预存款支付 主要处理
  157. * 如果预存款足够就单独支付了该订单,如果不足就暂时冻结,等API支付成功了再彻底扣除
  158. */
  159. public function pdPay($order_info, $input, $buyer_info) {
  160. if ($order_info['joinin_state'] == STORE_JOIN_STATE_FINAL)
  161. return $order_info;
  162. $available_pd_amount = floatval($buyer_info['available_predeposit']);
  163. if ($available_pd_amount <= 0)
  164. return $order_info;
  165. $predeposit_model = model('predeposit');
  166. $order_amount = round($order_info['paying_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'], 2);
  167. $data_pd = array();
  168. $data_pd['member_id'] = $buyer_info['member_id'];
  169. $data_pd['member_name'] = $buyer_info['member_name'];
  170. $data_pd['amount'] = $order_amount;
  171. $data_pd['order_sn'] = $order_info['pay_sn'];
  172. if ($available_pd_amount >= $order_amount) {
  173. //预存款立即支付,订单支付完成
  174. $predeposit_model->changePd('storejoinin_pay', $data_pd);
  175. $available_pd_amount -= $order_amount;
  176. //下单,支付被冻结的充值卡
  177. $pd_amount = floatval($order_info['rcb_amount']);
  178. if ($pd_amount > 0) {
  179. $data_pd = array();
  180. $data_pd['member_id'] = $buyer_info['member_id'];
  181. $data_pd['member_name'] = $buyer_info['member_name'];
  182. $data_pd['amount'] = $pd_amount;
  183. $data_pd['order_sn'] = $order_info['pay_sn'];
  184. $predeposit_model->changeRcb('order_comb_pay', $data_pd);
  185. }
  186. //支付被冻结的预存款
  187. $pd_amount = isset($order_info['pd_amount']) ? floatval($order_info['pd_amount']) : 0;
  188. if ($pd_amount > 0) {
  189. $data_pd = array();
  190. $data_pd['member_id'] = $buyer_info['member_id'];
  191. $data_pd['member_name'] = $buyer_info['member_name'];
  192. $data_pd['amount'] = $pd_amount;
  193. $data_pd['order_sn'] = $order_info['pay_sn'];
  194. $predeposit_model->changePd('storejoinin_comb_pay', $data_pd);
  195. }
  196. $store_model=model('store');
  197. $store_model->setStoreOpen($order_info,array('joinin_state'=>STORE_JOIN_STATE_FINAL,'payment_code'=>'predeposit'));
  198. // 订单状态 置为已支付
  199. $order_info['pd_amount'] = round($order_info['pd_amount'] + $order_amount, 2);
  200. } else {
  201. //暂冻结预存款,后面还需要 API彻底完成支付
  202. $data_pd['amount'] = $available_pd_amount;
  203. $predeposit_model->changePd('storejoinin_freeze', $data_pd);
  204. //预存款支付金额保存到订单
  205. $data_order = array();
  206. $order_info['pd_amount'] = $data_order['pd_amount'] = round($order_info['pd_amount'] + $available_pd_amount, 2);
  207. $result = $this->editStorejoinin($data_order, array('member_id' => $order_info['member_id']));
  208. if (!$result) {
  209. throw new \think\Exception('订单更新失败', 10006);
  210. }
  211. }
  212. return $order_info;
  213. }
  214. }