{"id":789,"date":"2012-08-30T12:09:28","date_gmt":"2012-08-30T04:09:28","guid":{"rendered":"http:\/\/home.wangjianshuo.com\/cn\/?p=789"},"modified":"2012-09-01T22:56:23","modified_gmt":"2012-09-01T14:56:23","slug":"192e","status":"publish","type":"post","link":"https:\/\/home.wangjianshuo.com\/cn\/20120830_192e.htm","title":{"rendered":"192\u884c"},"content":{"rendered":"<p>\/\/wangjianshuo@baixing.com<br \/>\nnamespace Graph;<\/p>\n<p>class CompanyAccount {<br \/>\n&#8230;function occuredRevenue($startTime, $endTime) {<br \/>\n&#8230;&#8230;$money = 0;<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;if($endTime &gt; time())<br \/>\n&#8230;&#8230;&#8230;throw new Exception(&#8220;Refuse to tell you future, because that may be inaccurate&#8221;);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;$s = new Searcher(<br \/>\n&#8230;&#8230;&#8230;new AndQuery(<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;type&#8217;, &#8216;Order&#8217;),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;paid&#8217;, 1),<br \/>\n&#8230;&#8230;&#8230;&#8230;new RangeQuery(&#8216;startTime&#8217;, null, $endTime),<br \/>\n&#8230;&#8230;&#8230;&#8230;new RangeQuery(&#8216;endTime&#8217;, $startTime &#8211; 1, null)<br \/>\n&#8230;&#8230;&#8230;)<br \/>\n&#8230;&#8230;);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;foreach($s as $order)<br \/>\n&#8230;&#8230;&#8230;$money += ($order-&gt;occuredRevenue($endTime) &#8211; $order-&gt;occuredRevenue($startTime));<br \/>\n&#8230;&#8230;&#8230;<br \/>\n&#8230;&#8230;return $money;<br \/>\n&#8230;}<br \/>\n}<\/p>\n<p>class UserAccount {<br \/>\n&#8230;public $balance; \/\/ money + credit;<br \/>\n&#8230;public $ratio; \/\/ money \/ balance;<br \/>\n&#8230;<br \/>\n&#8230;function in($money, $credit){<br \/>\n&#8230;&#8230;$this-&gt;ratio = ($this-&gt;balance * $this-&gt;ratio + $money) \/ ($this-&gt;balance + $money + $credit);<br \/>\n&#8230;&#8230;$this-&gt;balance += $money + $credit;<br \/>\n&#8230;&#8230;$this-&gt;save();<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function out($mondit) { \/\/mondit = money + credit<br \/>\n&#8230;&#8230;$this-&gt;balance -= $mondit;<br \/>\n&#8230;&#8230;$this-&gt;save();<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function pay($order) {<br \/>\n&#8230;&#8230;$order-&gt;pay($order-&gt;listPrice * $this-&gt;ratio);<br \/>\n&#8230;&#8230;$this-&gt;out($order-&gt;listPrice);<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function partialCancel($order, $time) {<br \/>\n&#8230;&#8230;$order-&gt;particalCancel($time);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;$refund = $order-&gt;price &#8211; $order-&gt;occuredRevenue($time);<br \/>\n&#8230;&#8230;$ratio = $order-&gt;price \/ $order-&gt;listPrice;<\/p>\n<p>&#8230;&#8230;$this-&gt;in($refund, $refund \/ $ratio * (1 &#8211; $ratio));<br \/>\n&#8230;}<br \/>\n}<\/p>\n<p>class Order {<br \/>\n&#8230;public $unitTime = 24 * 60 * 60; \/\/ 1 day<br \/>\n&#8230;public $paid = false;<br \/>\n&#8230;<br \/>\n&#8230;function occuredRevenue($time) {<br \/>\n&#8230;&#8230;$money = 0;<br \/>\n&#8230;&#8230;$unitPrice = round(($this-&gt;price) \/ ($this-&gt;endTime &#8211; $this-&gt;startTime) * $this-&gt;unitTime, 2);<br \/>\n&#8230;&#8230;for($i = 0; $occuredTime = $this-&gt;startTime + $this-&gt;unitTime * $i, $occuredTime &lt; min($time, $endTime); $i++)<br \/>\n&#8230;&#8230;&#8230;if($this-&gt;endTime &#8211; $this-&gt;occuredTime &lt;= $this-&gt;unitTime)<br \/>\n&#8230;&#8230;&#8230;&#8230;$money += ($this-&gt;price &#8211; $unitPrice * $i);<br \/>\n&#8230;&#8230;&#8230;else<br \/>\n&#8230;&#8230;&#8230;&#8230;$money += $unitPrice;<br \/>\n&#8230;&#8230;return $money;&#8230;&#8230;<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function place() {<br \/>\n&#8230;&#8230;$pa = new BiddingPrice();<br \/>\n&#8230;&#8230;$this-&gt;listPrice = $pa-&gt;price($order);<br \/>\n&#8230;&#8230;$this-&gt;save();<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function partialCancel($time) {<br \/>\n&#8230;&#8230;if($time &gt;= $this-&gt;endTime)<br \/>\n&#8230;&#8230;&#8230;throw new Exception(&#8216;Cannot cancel completed order&#8217;);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;$neg = clone $this;<br \/>\n&#8230;&#8230;$neg-&gt;startTime = max($this-&gt;startTime, $time);<br \/>\n&#8230;&#8230;$neg-&gt;price = $this-&gt;occuredRevenue($time) &#8211; $this-&gt;price;<br \/>\n&#8230;&#8230;$neg-&gt;save();<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function attributes() {<br \/>\n&#8230;&#8230;$ad = graph($this-&gt;adId);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;return array_merge(<br \/>\n&#8230;&#8230;&#8230;parent::attributes(),<br \/>\n&#8230;&#8230;&#8230;&#8217;categories&#8217; =&gt; cg_array_upto(array_reverse($ad-&gt;category-&gt;path()), $this-&gt;category),<br \/>\n&#8230;&#8230;&#8230;&#8217;areas&#8217; =&gt; cg_array_upto(array_reverse($ad-&gt;area-&gt;path()), $this-&gt;area)<br \/>\n&#8230;}<br \/>\n}<\/p>\n<p>function cg_array_upto($arr, $c) {<br \/>\n&#8230;$result = array();<br \/>\n&#8230;<br \/>\n&#8230;foreach($arr as $a) {<br \/>\n&#8230;&#8230;$result[] = $a;<br \/>\n&#8230;&#8230;$if($a == $c)<br \/>\n&#8230;&#8230;&#8230;break;<br \/>\n&#8230;}<br \/>\n&#8230;return $result;<br \/>\n}<\/p>\n<p>class DingPrice extends BiddingPrice {<br \/>\n&#8230;public $capacity = 12;<br \/>\n&#8230;public $sensitivity = 0.5;<br \/>\n&#8230;public $bottom = 3;<br \/>\n&#8230;public $tolerance = 30; \/\/ day<br \/>\n&#8230;public $basePrice = 10; \/\/ RMB<br \/>\n}<\/p>\n<p>class RefreshPrice extends BiddingPrice {<br \/>\n&#8230;public $capacity = 12;<br \/>\n&#8230;public $sensitivity = 0.5;<br \/>\n&#8230;public $bottom = 3;<br \/>\n&#8230;public $tolerance = 30; \/\/ day<br \/>\n&#8230;public $basePrice = 10; \/\/ RMB<br \/>\n}<\/p>\n<p>class BiddingPrice {<br \/>\n&#8230;function price($order) {<br \/>\n&#8230;&#8230;$s = new Searcher(<br \/>\n&#8230;&#8230;&#8230;new AndQuery(<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;type&#8217;, &#8216;Order&#8217;),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;paid&#8217;, 1),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;area&#8217;, $order-&gt;area),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;category&#8217;, $order-&gt;category)<br \/>\n&#8230;&#8230;&#8230;),<br \/>\n&#8230;&#8230;&#8230;array(&#8216;order&#8217; =&gt; &#8216;startTime DESC&#8217;)<br \/>\n&#8230;&#8230;);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;if(count($s) == 0)<br \/>\n&#8230;&#8230;&#8230;return $this-&gt;basePrice;<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;$currentPrice = $s[0]-&gt;listPrice;<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;if(count($s) &gt; $this-&gt;capacity) {<br \/>\n&#8230;&#8230;&#8230;foreach(array_slice($s, 0 floor($this-&gt;sensitivity * $this-&gt;capacity) as $o)<br \/>\n&#8230;&#8230;&#8230;&#8230;if($o-&gt;listPrice != $currentPrice)<br \/>\n&#8230;&#8230;&#8230;&#8230;&#8230;return $currentPrice;<br \/>\n&#8230;&#8230;&#8230;return $this-&gt;increase($currentPrice);<br \/>\n&#8230;&#8230;}<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;if(count($s) &lt;= $this-&gt;bottom &amp;&amp;<br \/>\n&#8230;&#8230;&#8230;time() &#8211; $s[0]-&gt;startTime &gt; $this-&gt;tolerance)<br \/>\n&#8230;&#8230;&#8230;return $this-&gt;decrease($currentPrice);<br \/>\n&#8230;&#8230;&#8230;<br \/>\n&#8230;&#8230;return $currentPrice;<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function increase($price) {<br \/>\n&#8230;&#8230;return $price + 10;<br \/>\n&#8230;}<br \/>\n&#8230;<br \/>\n&#8230;function decrease($price) {<br \/>\n&#8230;&#8230;return $price &#8211; 10;<br \/>\n&#8230;}<br \/>\n}<\/p>\n<p>class DingAds {<br \/>\n&#8230;function ads() {<br \/>\n&#8230;&#8230;$v = new Visitor();<br \/>\n&#8230;&#8230;$s = new Searcher(<br \/>\n&#8230;&#8230;&#8230;new AndQuery(<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;type&#8217;, &#8216;Order&#8217;),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;paid&#8217;, 1),<br \/>\n&#8230;&#8230;&#8230;&#8230;new RangQuery(&#8216;startTime&#8217;, null, time() + 1),<br \/>\n&#8230;&#8230;&#8230;&#8230;new RangeQuery(&#8216;endTime&#8217;, time(), null),<br \/>\n&#8230;&#8230;&#8230;&#8230;new Query(&#8216;categories&#8217;, $v-&gt;category),<br \/>\n&#8230;&#8230;&#8230;&#8230;new InQuery(&#8216;areas&#8217;, $v-&gt;area-&gt;path())<br \/>\n&#8230;&#8230;&#8230;&#8230;)<br \/>\n&#8230;&#8230;&#8230;)<br \/>\n&#8230;&#8230;);<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;$dingAds = array();<br \/>\n&#8230;&#8230;$negAds = array();<br \/>\n&#8230;&#8230;<br \/>\n&#8230;&#8230;foreach($s as $o)<br \/>\n&#8230;&#8230;&#8230;if($o-&gt;price &gt;= 0)<br \/>\n&#8230;&#8230;&#8230;&#8230;$dingAds[] = $o-&gt;id;<br \/>\n&#8230;&#8230;&#8230;else<br \/>\n&#8230;&#8230;&#8230;&#8230;$negAds[] = $o-&gt;id;<br \/>\n&#8230;&#8230;&#8230;&#8230;<br \/>\n&#8230;&#8230;return array_diff($dingAds, $negAds);<br \/>\n&#8230;}<br \/>\n}<br \/>\n\/**<br \/>\n* 1. AccuralBasedAccouting DONE<br \/>\n* 2. Ding (Category, Filter, City, Province, China) DONE<br \/>\n* 3. Place order, pay, refund, partialCancel DONE<br \/>\n* 4. Pricing (Ding bidding based pricing, Refresh bidding, list bidding) DONE<br \/>\n* 5. User Account, real money, fake money DONE<br \/>\n* 6. Ding display DONE<br \/>\n* 7) Refresh 5 RMB<br \/>\n* 8) listing fee 10 RMB<br \/>\n* 9) Sales tools<br \/>\n* 10) Automatic invoice<br \/>\n* 11) Port service<br \/>\n*<br \/>\n* o&#8212;&#8211;o&#8212;&#8211;o&#8212;&#8211;o&#8212;&#8211;\u00f8&#8211;<br \/>\n* ^ time<br \/>\n* o&#8212;&#8211;o&#8212;&#8211;o&#8212;&#8211;o&#8212;&#8211;o&#8212;-<br \/>\n*<br \/>\n*&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;o&#8212;&#8211;o&#8212;&#8211;<br \/>\n*<br \/>\n* |&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;|<br \/>\n* ^ startTime ^ endTime<br \/>\n*<br \/>\n* Order<br \/>\n* =====<br \/>\n* orderId<br \/>\n* starTime<br \/>\n* endTime<br \/>\n* listPrice<br \/>\n* price<br \/>\n* paid<br \/>\n* area<br \/>\n* category<br \/>\n* adId<br \/>\n*<br \/>\n* 1. Order never change after paid.<br \/>\n* 2. Range [startTime, endTime)<br \/>\n* 3. price, money refer to real money,<br \/>\n* 4. listPrice, $credit refer to fake money.<br \/>\n*\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/wangjianshuo@baixing.com namespace Graph; class Compa &hellip; <a href=\"https:\/\/home.wangjianshuo.com\/cn\/20120830_192e.htm\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">192\u884c<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,47],"tags":[],"_links":{"self":[{"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/posts\/789"}],"collection":[{"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/comments?post=789"}],"version-history":[{"count":10,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/posts\/789\/revisions"}],"predecessor-version":[{"id":798,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/posts\/789\/revisions\/798"}],"wp:attachment":[{"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/media?parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/categories?post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/home.wangjianshuo.com\/cn\/wp-json\/wp\/v2\/tags?post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}